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
This commit is contained in:
Miguel Pozo
2025-10-08 16:48:38 +02:00
parent 71f4277467
commit 75f3d8c68f

View File

@@ -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