Fix T97686 DRW: Freeze when switching to material preview or render view
This was caused by the compilation job being created suspended (to avoid UI slowdown because of the material Preview Icons). The suspended job wasn't passing the `WM_jobs_test` in `DRW_deferred_shader_remove` and the material would still be in the compile queue with its status equal to `GPU_MAT_QUEUED`. This would block the main thread in the waiting loop. But since the job manager timer needs to execute in the main thread, the compilation job was never being pushed out of its suspended state. This lead to a complete lock situation. The solution is to use `WM_jobs_customdata_from_type` which does exactly what we need. Also fixed a nullptr free.
This commit is contained in:
@@ -237,16 +237,10 @@ static void drw_deferred_shader_add(GPUMaterial *mat, bool deferred)
|
||||
|
||||
void DRW_deferred_shader_remove(GPUMaterial *mat)
|
||||
{
|
||||
for (wmWindowManager *wm = G_MAIN->wm.first; wm; wm = wm->id.next) {
|
||||
if (WM_jobs_test(wm, wm, WM_JOB_TYPE_SHADER_COMPILATION) == false) {
|
||||
/* No job running, do not create a new one by calling WM_jobs_get. */
|
||||
continue;
|
||||
}
|
||||
LISTBASE_FOREACH (wmWindowManager *, wm, &G_MAIN->wm) {
|
||||
LISTBASE_FOREACH (wmWindow *, win, &wm->windows) {
|
||||
wmJob *wm_job = WM_jobs_get(
|
||||
wm, win, wm, "Shaders Compilation", 0, WM_JOB_TYPE_SHADER_COMPILATION);
|
||||
|
||||
DRWShaderCompiler *comp = (DRWShaderCompiler *)WM_jobs_customdata_get(wm_job);
|
||||
DRWShaderCompiler *comp = (DRWShaderCompiler *)WM_jobs_customdata_from_type(
|
||||
wm, wm, WM_JOB_TYPE_SHADER_COMPILATION);
|
||||
if (comp != NULL) {
|
||||
BLI_spin_lock(&comp->list_lock);
|
||||
LinkData *link = (LinkData *)BLI_findptr(&comp->queue, mat, offsetof(LinkData, data));
|
||||
@@ -256,7 +250,7 @@ void DRW_deferred_shader_remove(GPUMaterial *mat)
|
||||
}
|
||||
BLI_spin_unlock(&comp->list_lock);
|
||||
|
||||
MEM_freeN(link);
|
||||
MEM_SAFE_FREE(link);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user