Render: Only run callbacks for non-preview renders
authorSergey Sharybin <sergey.vfx@gmail.com>
Mon, 9 Sep 2019 14:39:07 +0000 (16:39 +0200)
committerSergey Sharybin <sergey.vfx@gmail.com>
Wed, 11 Sep 2019 08:43:27 +0000 (10:43 +0200)
Those handlers are usually done to edit scene which is being rendered,
and this is not supported due to a fully localized nature of the preview
bmain.

There is still non-conditional callback in stats_background which is a
bit tricky to cover with check, but this code is not supposed to be run
for previews anyway.

Reviewers: brecht

Differential Revision: https://developer.blender.org/D5731

source/blender/render/intern/source/pipeline.c

index 2c379700c801331638ef8d89a4500650856bc32c..fdb90a6e91e7aef28e6de481429b42aeb40ff069 100644 (file)
@@ -134,6 +134,24 @@ static struct {
   ListBase renderlist;
 } RenderGlobal = {{NULL, NULL}};
 
+/* ********* callbacks ******** */
+
+static void render_callback_exec_null(Render *re, Main *bmain, eCbEvent evt)
+{
+  if (re->r.scemode & R_BUTS_PREVIEW) {
+    return;
+  }
+  BKE_callback_exec_null(bmain, evt);
+}
+
+static void render_callback_exec_id(Render *re, Main *bmain, ID *id, eCbEvent evt)
+{
+  if (re->r.scemode & R_BUTS_PREVIEW) {
+    return;
+  }
+  BKE_callback_exec_id(bmain, id, evt);
+}
+
 /* ********* alloc and free ******** */
 
 static int do_write_image_or_movie(Render *re,
@@ -2090,7 +2108,7 @@ void RE_RenderFrame(Render *re,
                     int frame,
                     const bool write_still)
 {
-  BKE_callback_exec_id(re->main, &scene->id, BKE_CB_EVT_RENDER_INIT);
+  render_callback_exec_id(re, re->main, &scene->id, BKE_CB_EVT_RENDER_INIT);
 
   /* Ugly global still...
    * is to prevent preview events and signal subsurfs etc to make full resol. */
@@ -2103,7 +2121,7 @@ void RE_RenderFrame(Render *re,
     const RenderData rd = scene->r;
     MEM_reset_peak_memory();
 
-    BKE_callback_exec_id(re->main, &scene->id, BKE_CB_EVT_RENDER_PRE);
+    render_callback_exec_id(re, re->main, &scene->id, BKE_CB_EVT_RENDER_PRE);
 
     render_init_depsgraph(re);
 
@@ -2131,14 +2149,16 @@ void RE_RenderFrame(Render *re,
     }
 
     /* keep after file save */
-    BKE_callback_exec_id(re->main, &scene->id, BKE_CB_EVT_RENDER_POST);
+    render_callback_exec_id(re, re->main, &scene->id, BKE_CB_EVT_RENDER_POST);
     if (write_still) {
-      BKE_callback_exec_id(re->main, &scene->id, BKE_CB_EVT_RENDER_WRITE);
+      render_callback_exec_id(re, re->main, &scene->id, BKE_CB_EVT_RENDER_WRITE);
     }
   }
 
-  BKE_callback_exec_id(
-      re->main, &scene->id, G.is_break ? BKE_CB_EVT_RENDER_CANCEL : BKE_CB_EVT_RENDER_COMPLETE);
+  render_callback_exec_id(re,
+                          re->main,
+                          &scene->id,
+                          G.is_break ? BKE_CB_EVT_RENDER_CANCEL : BKE_CB_EVT_RENDER_COMPLETE);
 
   RE_CleanAfterRender(re);
 
@@ -2429,7 +2449,7 @@ static int do_write_image_or_movie(Render *re,
 
   /* NOTE: using G_MAIN seems valid here???
    * Not sure it's actually even used anyway, we could as well pass NULL? */
-  BKE_callback_exec_null(G_MAIN, BKE_CB_EVT_RENDER_STATS);
+  render_callback_exec_null(re, G_MAIN, BKE_CB_EVT_RENDER_STATS);
 
   BLI_timecode_string_from_time_simple(name, sizeof(name), re->i.lastframetime - render_time);
   printf(" (Saving: %s)\n", name);
@@ -2495,7 +2515,7 @@ void RE_RenderAnim(Render *re,
   const bool is_multiview_name = ((rd.scemode & R_MULTIVIEW) != 0 &&
                                   (rd.im_format.views_format == R_IMF_VIEWS_INDIVIDUAL));
 
-  BKE_callback_exec_id(re->main, &scene->id, BKE_CB_EVT_RENDER_INIT);
+  render_callback_exec_id(re, re->main, &scene->id, BKE_CB_EVT_RENDER_INIT);
 
   /* do not fully call for each frame, it initializes & pops output window */
   if (!render_initialize_from_main(re, &rd, bmain, scene, single_layer, camera_override, 0, 1)) {
@@ -2661,7 +2681,7 @@ void RE_RenderAnim(Render *re,
       re->r.cfra = scene->r.cfra; /* weak.... */
 
       /* run callbacks before rendering, before the scene is updated */
-      BKE_callback_exec_id(re->main, &scene->id, BKE_CB_EVT_RENDER_PRE);
+      render_callback_exec_id(re, re->main, &scene->id, BKE_CB_EVT_RENDER_PRE);
 
       do_render_all_options(re);
       totrendered++;
@@ -2712,8 +2732,8 @@ void RE_RenderAnim(Render *re,
 
       if (G.is_break == false) {
         /* keep after file save */
-        BKE_callback_exec_id(re->main, &scene->id, BKE_CB_EVT_RENDER_POST);
-        BKE_callback_exec_id(re->main, &scene->id, BKE_CB_EVT_RENDER_WRITE);
+        render_callback_exec_id(re, re->main, &scene->id, BKE_CB_EVT_RENDER_POST);
+        render_callback_exec_id(re, re->main, &scene->id, BKE_CB_EVT_RENDER_WRITE);
       }
     }
   }
@@ -2731,8 +2751,10 @@ void RE_RenderAnim(Render *re,
 
   re->flag &= ~R_ANIMATION;
 
-  BKE_callback_exec_id(
-      re->main, &scene->id, G.is_break ? BKE_CB_EVT_RENDER_CANCEL : BKE_CB_EVT_RENDER_COMPLETE);
+  render_callback_exec_id(re,
+                          re->main,
+                          &scene->id,
+                          G.is_break ? BKE_CB_EVT_RENDER_CANCEL : BKE_CB_EVT_RENDER_COMPLETE);
   BKE_sound_reset_scene_specs(re->pipeline_scene_eval);
 
   RE_CleanAfterRender(re);