Eevee: Fix crash when clicking the lightcache bake button multiple time

This commit is contained in:
Clément Foucault 2018-10-23 17:27:10 +02:00
parent ee8e866a0e
commit 8e8d1cab6f
1 changed files with 25 additions and 1 deletions

View File

@ -146,6 +146,8 @@ typedef struct EEVEE_LightBake {
int delay; /* ms. delay the start of the baking to not slowdown interactions (TODO remove) */
void *gl_context, *gpu_context; /* If running in parallel (in a separate thread), use this context. */
ThreadMutex *mutex;
} EEVEE_LightBake;
/* -------------------------------------------------------------------- */
@ -518,6 +520,11 @@ wmJob *EEVEE_lightbake_job_create(
/* lbake->depsgraph = old_lbake->depsgraph; */
lbake->depsgraph = DEG_graph_new(scene, view_layer, DAG_EVAL_RENDER);
lbake->mutex = BLI_mutex_alloc();
BLI_mutex_lock(old_lbake->mutex);
old_lbake->own_resources = false;
lbake->scene = scene;
lbake->bmain = bmain;
lbake->view_layer_input = view_layer;
@ -525,11 +532,15 @@ wmJob *EEVEE_lightbake_job_create(
lbake->own_resources = true;
lbake->delay = delay;
old_lbake->own_resources = false;
if (lbake->gl_context == NULL) {
lbake->gl_context = WM_opengl_context_create();
wm_window_reset_drawable();
}
if (old_lbake->stop != NULL) {
*old_lbake->stop = 1;
}
BLI_mutex_unlock(old_lbake->mutex);
}
else {
lbake = EEVEE_lightbake_job_data_alloc(bmain, view_layer, scene, true);
@ -559,6 +570,7 @@ void *EEVEE_lightbake_job_data_alloc(
lbake->view_layer_input = view_layer;
lbake->own_resources = true;
lbake->own_light_cache = false;
lbake->mutex = BLI_mutex_alloc();
if (run_as_job) {
lbake->gl_context = WM_opengl_context_create();
@ -572,6 +584,8 @@ void EEVEE_lightbake_job_data_free(void *custom_data)
{
EEVEE_LightBake *lbake = (EEVEE_LightBake *)custom_data;
/* TODO reuse depsgraph. */
/* if (lbake->own_resources) { */
DEG_graph_free(lbake->depsgraph);
@ -580,11 +594,17 @@ void EEVEE_lightbake_job_data_free(void *custom_data)
MEM_SAFE_FREE(lbake->cube_prb);
MEM_SAFE_FREE(lbake->grid_prb);
BLI_mutex_free(lbake->mutex);
MEM_freeN(lbake);
}
static void eevee_lightbake_delete_resources(EEVEE_LightBake *lbake)
{
if (!lbake->resource_only) {
BLI_mutex_lock(lbake->mutex);
}
if (lbake->gl_context) {
DRW_opengl_render_context_enable(lbake->gl_context);
DRW_gawain_render_context_enable(lbake->gpu_context);
@ -631,6 +651,10 @@ static void eevee_lightbake_delete_resources(EEVEE_LightBake *lbake)
else if (!lbake->resource_only) {
DRW_opengl_context_disable();
}
if (!lbake->resource_only) {
BLI_mutex_unlock(lbake->mutex);
}
}
/* Cache as in draw cache not light cache. */