Fix Cycles headless render failing, after grease pencil merge.
authorBrecht Van Lommel <brechtvanlommel@gmail.com>
Wed, 1 Aug 2018 12:21:50 +0000 (14:21 +0200)
committerBrecht Van Lommel <brechtvanlommel@gmail.com>
Wed, 1 Aug 2018 12:47:02 +0000 (14:47 +0200)
Now it should at least succeed when there are no grease pencil objects.

source/blender/draw/intern/draw_manager.c
source/blender/render/intern/source/external_engine.c

index ba53c3aa66414a491059c4147b17cdbfe1ec3fe0..5140e379aafb4495807ee70c2d8bd626f71e6ec4 100644 (file)
@@ -1619,11 +1619,11 @@ void DRW_draw_render_loop_offscreen(
 }
 
 /* helper to check if exit object type to render */
-static bool DRW_render_check_object_type(struct Depsgraph *depsgraph, short obtype)
+static bool DRW_render_check_grease_pencil(Depsgraph *depsgraph)
 {
        DEG_OBJECT_ITER_FOR_RENDER_ENGINE_BEGIN(depsgraph, ob)
        {
-               if ((ob->type == obtype) && (DRW_check_object_visible_within_active_context(ob))) {
+               if ((ob->type == OB_GPENCIL) && (DRW_check_object_visible_within_active_context(ob))) {
                        return true;
                }
        }
@@ -1632,13 +1632,11 @@ static bool DRW_render_check_object_type(struct Depsgraph *depsgraph, short obty
        return false;
 }
 
-static void DRW_render_gpencil_to_image(RenderEngine *engine, struct Depsgraph *depsgraph, struct RenderLayer *render_layer, const rcti *rect)
+static void DRW_render_gpencil_to_image(RenderEngine *engine, struct RenderLayer *render_layer, const rcti *rect)
 {
        if (draw_engine_gpencil_type.render_to_image) {
-               if (DRW_render_check_object_type(depsgraph, OB_GPENCIL)) {
-                       ViewportEngineData *gpdata = drw_viewport_engine_data_ensure(&draw_engine_gpencil_type);
-                       draw_engine_gpencil_type.render_to_image(gpdata, engine, render_layer, rect);
-               }
+               ViewportEngineData *gpdata = drw_viewport_engine_data_ensure(&draw_engine_gpencil_type);
+               draw_engine_gpencil_type.render_to_image(gpdata, engine, render_layer, rect);
        }
 }
 
@@ -1652,6 +1650,12 @@ void DRW_render_gpencil(struct RenderEngine *engine, struct Depsgraph *depsgraph
                return;
        }
 
+       /* Early out if there are no grease pencil objects, especially important
+        * to avoid failing in in background renders without OpenGL context. */
+       if (!DRW_render_check_grease_pencil(depsgraph)) {
+               return;
+       }
+
        Scene *scene = DEG_get_evaluated_scene(depsgraph);
        ViewLayer *view_layer = DEG_get_evaluated_view_layer(depsgraph);
        RenderEngineType *engine_type = engine->type;
@@ -1712,7 +1716,7 @@ void DRW_render_gpencil(struct RenderEngine *engine, struct Depsgraph *depsgraph
        RenderResult *render_result = RE_engine_get_result(engine);
        RenderLayer *render_layer = render_result->layers.first;
 
-       DRW_render_gpencil_to_image(engine, depsgraph, render_layer, &render_rect);
+       DRW_render_gpencil_to_image(engine, render_layer, &render_rect);
 
        /* Force cache to reset. */
        drw_viewport_cache_resize();
@@ -1814,7 +1818,9 @@ void DRW_render_to_image(RenderEngine *engine, struct Depsgraph *depsgraph)
                RE_SetActiveRenderView(render, render_view->name);
                engine_type->draw_engine->render_to_image(data, engine, render_layer, &render_rect);
                /* grease pencil: render result is merged in the previous render result. */
-               DRW_render_gpencil_to_image(engine, depsgraph, render_layer, &render_rect);
+               if (DRW_render_check_grease_pencil(depsgraph)) {
+                       DRW_render_gpencil_to_image(engine, render_layer, &render_rect);
+               }
                DST.buffer_finish_called = false;
        }
 
index 0b27cadd086242a19acb7df35e6a7b8a33b7f223..09ab3e39d5ff3fee2f28b3bcd548805b99a84a33 100644 (file)
@@ -740,9 +740,15 @@ int RE_engine_render(Render *re, int do_all)
                        type->render(engine, engine->depsgraph);
 
                        /* grease pencil render over previous render result */
-                       DRW_render_gpencil(engine, engine->depsgraph);
+                       if (!RE_engine_test_break(engine)) {
+                               DRW_render_gpencil(engine, engine->depsgraph);
+                       }
 
                        engine_depsgraph_free(engine);
+
+                       if (RE_engine_test_break(engine)) {
+                               break;
+                       }
                }
                FOREACH_VIEW_LAYER_TO_RENDER_END;
        }