From 75f3d8c68f582ea29340b89cafce8f4655695ff8 Mon Sep 17 00:00:00 2001 From: Miguel Pozo Date: Wed, 8 Oct 2025 16:48:38 +0200 Subject: [PATCH] Fix #147483: Crash switching scene while rendering animation in main window When rendering in the main window and changing the active scene, RE_FreeUnusedGPUResources can free the resources of an active Render, since no wmWindow references the Scene anymore. Active Render instances always reference their Scene, so we check those directly instead. Pull Request: https://projects.blender.org/blender/blender/pulls/147553 --- source/blender/render/intern/pipeline.cc | 26 ++++++++++++++---------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/source/blender/render/intern/pipeline.cc b/source/blender/render/intern/pipeline.cc index 1d901657a5e..c2b1d3ffdc2 100644 --- a/source/blender/render/intern/pipeline.cc +++ b/source/blender/render/intern/pipeline.cc @@ -684,20 +684,24 @@ void RE_FreeUnusedGPUResources() for (Render *re : RenderGlobal.render_list) { bool do_free = true; + const Scene *scene = RE_GetScene(re); + /* Don't free scenes being rendered or composited. Note there is no + * race condition here because we are on the main thread and new jobs can only + * be started from the main thread. */ + if (WM_jobs_test(wm, scene, WM_JOB_TYPE_RENDER) || + WM_jobs_test(wm, scene, WM_JOB_TYPE_COMPOSITE)) + { + do_free = false; + } + LISTBASE_FOREACH (const wmWindow *, win, &wm->windows) { - const Scene *scene = WM_window_get_active_scene(win); - if (re != RE_GetSceneRender(scene)) { - continue; + if (!do_free) { + /* No need to do further checks. */ + break; } - /* Don't free if this scene is being rendered or composited. Note there is no - * race condition here because we are on the main thread and new jobs can only - * be started from the main thread. */ - if (WM_jobs_test(wm, scene, WM_JOB_TYPE_RENDER) || - WM_jobs_test(wm, scene, WM_JOB_TYPE_COMPOSITE)) - { - do_free = false; - break; + if (WM_window_get_active_scene(win) != scene) { + continue; } /* Detect if scene is using GPU compositing, and if either a node editor is