Fix undo crash with multiple scenes & windows

Creating a new window then a new scene would crash on undo
because the undo step loaded would not contain the new windows scene.

Regression introduced since 3.6.
This commit is contained in:
Campbell Barton
2023-10-26 22:18:40 +11:00
parent 0e4a3bd7aa
commit 4f0d8931f0

View File

@@ -800,6 +800,19 @@ static void setup_app_data(bContext *C,
wm_data_consistency_ensure(CTX_wm_manager(C), curscene, cur_view_layer);
}
if (mode == LOAD_UNDO) {
/* It's possible to undo into a time before the scene existed, in this case the window's scene
* will be null. Since it doesn't make sense to remove the window, set it to the current scene.
* NOTE: Redo will restore the active scene to the window so a reasonably consistent state
* is maintained. We could do better by keeping a window/scene map for each undo step. */
wmWindowManager *wm = static_cast<wmWindowManager *>(bfd->main->wm.first);
LISTBASE_FOREACH (wmWindow *, win, &wm->windows) {
if (win->scene == nullptr) {
win->scene = curscene;
}
}
}
BLI_assert(BKE_main_namemap_validate(bfd->main));
if (mode != LOAD_UI) {