diff --git a/source/blender/draw/intern/draw_manager.c b/source/blender/draw/intern/draw_manager.c index 699ac8d5b0b..989f576435a 100644 --- a/source/blender/draw/intern/draw_manager.c +++ b/source/blender/draw/intern/draw_manager.c @@ -2830,6 +2830,7 @@ void DRW_opengl_context_destroy(void) void DRW_opengl_context_enable_ex(bool restore) { if (DST.gl_context != NULL) { + BLI_thread_lock(LOCK_OPENGL); /* IMPORTANT: We dont support immediate mode in render mode! * This shall remain in effect until immediate mode supports * multiple threads. */ @@ -2868,6 +2869,7 @@ void DRW_opengl_context_disable_ex(bool restore) } BLI_ticket_mutex_unlock(DST.gl_context_mutex); + BLI_thread_unlock(LOCK_OPENGL); } } @@ -2890,6 +2892,7 @@ void DRW_opengl_render_context_enable(void *re_gl_context) BLI_assert(!BLI_thread_is_main()); /* TODO get rid of the blocking. Only here because of the static global DST. */ + BLI_thread_lock(LOCK_OPENGL); BLI_ticket_mutex_lock(DST.gl_context_mutex); WM_opengl_context_activate(re_gl_context); } @@ -2900,6 +2903,7 @@ void DRW_opengl_render_context_disable(void *re_gl_context) WM_opengl_context_release(re_gl_context); /* TODO get rid of the blocking. */ BLI_ticket_mutex_unlock(DST.gl_context_mutex); + BLI_thread_unlock(LOCK_OPENGL); } /* Needs to be called AFTER DRW_opengl_render_context_enable() */ diff --git a/source/blender/gpu/intern/gpu_draw.c b/source/blender/gpu/intern/gpu_draw.c index c9989703d5b..91f57dfdb7c 100644 --- a/source/blender/gpu/intern/gpu_draw.c +++ b/source/blender/gpu/intern/gpu_draw.c @@ -1121,12 +1121,13 @@ void GPU_free_smoke_velocity(SmokeModifierData *smd) } static LinkNode *image_free_queue = NULL; +static ThreadMutex img_queue_mutex = BLI_MUTEX_INITIALIZER; static void gpu_queue_image_for_free(Image *ima) { - BLI_thread_lock(LOCK_OPENGL); + BLI_mutex_lock(&img_queue_mutex); BLI_linklist_prepend(&image_free_queue, ima); - BLI_thread_unlock(LOCK_OPENGL); + BLI_mutex_unlock(&img_queue_mutex); } void GPU_free_unused_buffers(Main *bmain) @@ -1135,6 +1136,7 @@ void GPU_free_unused_buffers(Main *bmain) return; BLI_thread_lock(LOCK_OPENGL); + BLI_mutex_lock(&img_queue_mutex); /* images */ for (LinkNode *node = image_free_queue; node; node = node->next) { @@ -1148,6 +1150,7 @@ void GPU_free_unused_buffers(Main *bmain) BLI_linklist_free(image_free_queue, NULL); image_free_queue = NULL; + BLI_mutex_unlock(&img_queue_mutex); BLI_thread_unlock(LOCK_OPENGL); }