Fix threading issues of viewport rendering when using movies/generated images
[blender.git] / source / blender / render / intern / source / external_engine.c
index 296c8b6eba8dd9e6f50e524ed6ae5660ec835eb7..22a49bcbbc388c725994ea174a0928faae98bc60 100644 (file)
@@ -1,4 +1,5 @@
 /*
+
  * ***** BEGIN GPL LICENSE BLOCK *****
  *
  * This program is free software; you can redistribute it and/or
@@ -127,10 +128,21 @@ int RE_engine_is_external(Render *re)
 /* Create, Free */
 
 RenderEngine *RE_engine_create(RenderEngineType *type)
+{
+       return RE_engine_create_ex(type, FALSE);
+}
+
+RenderEngine *RE_engine_create_ex(RenderEngineType *type, int use_for_viewport)
 {
        RenderEngine *engine = MEM_callocN(sizeof(RenderEngine), "RenderEngine");
        engine->type = type;
 
+       if (use_for_viewport) {
+               engine->flag |= RE_ENGINE_USED_FOR_VIEWPORT;
+
+               BLI_begin_threaded_malloc();
+       }
+
        return engine;
 }
 
@@ -142,6 +154,10 @@ void RE_engine_free(RenderEngine *engine)
        }
 #endif
 
+       if (engine->flag & RE_ENGINE_USED_FOR_VIEWPORT) {
+               BLI_end_threaded_malloc();
+       }
+
        if (engine->text)
                MEM_freeN(engine->text);