diff options
author | Clément Foucault <foucault.clem@gmail.com> | 2018-07-27 14:57:46 +0300 |
---|---|---|
committer | Clément Foucault <foucault.clem@gmail.com> | 2018-07-27 14:57:46 +0300 |
commit | 6a05c14a8a24219e43ea82012762e63bd3b2a93f (patch) | |
tree | e31c3d2176aad3e60dd795544e79c1bd454dd208 /source/blender/draw/intern/draw_manager_shader.c | |
parent | 141e94f87ff29452ed8df82b4c25d8d134a34dad (diff) |
DRW: Fix Race condition in defered compilation
Diffstat (limited to 'source/blender/draw/intern/draw_manager_shader.c')
-rw-r--r-- | source/blender/draw/intern/draw_manager_shader.c | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/source/blender/draw/intern/draw_manager_shader.c b/source/blender/draw/intern/draw_manager_shader.c index b0aec4a7600..b85e6267687 100644 --- a/source/blender/draw/intern/draw_manager_shader.c +++ b/source/blender/draw/intern/draw_manager_shader.c @@ -72,6 +72,7 @@ typedef struct DRWShaderCompiler { ThreadMutex compilation_lock; void *gl_context; + bool own_context; int shaders_done; /* To compute progress. */ } DRWShaderCompiler; @@ -146,7 +147,7 @@ static void drw_deferred_shader_compilation_free(void *custom_data) BLI_spin_end(&comp->list_lock); BLI_mutex_end(&comp->compilation_lock); - if (comp->gl_context) { + if (comp->own_context) { /* Only destroy if the job owns the context. */ WM_opengl_context_dispose(comp->gl_context); } @@ -189,8 +190,11 @@ static void drw_deferred_shader_add(GPUMaterial *mat, bool deferred) BLI_movelisttolist(&comp->queue, &old_comp->queue); BLI_spin_unlock(&old_comp->list_lock); /* Do not recreate context, just pass ownership. */ - comp->gl_context = old_comp->gl_context; - old_comp->gl_context = NULL; + if (old_comp->gl_context) { + comp->gl_context = old_comp->gl_context; + old_comp->own_context = false; + comp->own_context = true; + } } BLI_addtail(&comp->queue, dsh); @@ -199,6 +203,7 @@ static void drw_deferred_shader_add(GPUMaterial *mat, bool deferred) if (comp->gl_context == NULL) { comp->gl_context = WM_opengl_context_create(); WM_opengl_context_activate(DST.gl_context); + comp->own_context = true; } WM_jobs_customdata_set(wm_job, comp, drw_deferred_shader_compilation_free); |