Fix T92357: assert changing scenes while in edit mode

ScrArea.runtime.tool needs to be updated after switching scenes.
This commit is contained in:
Campbell Barton 2021-10-22 10:12:01 +11:00
parent bdbaf0301d
commit 3e1baa7d53
Notes: blender-bot 2023-02-14 05:37:19 +01:00
Referenced by commit 7e02c90103, Fix WM_toolsystem_refresh_screen_all failing to refresh tools
Referenced by issue #92357, Assert fails when entering another scene while in edit mode
5 changed files with 36 additions and 19 deletions

View File

@ -210,7 +210,10 @@ void ED_screen_ensure_updated(struct wmWindowManager *wm,
struct bScreen *screen);
void ED_screen_do_listen(struct bContext *C, struct wmNotifier *note);
bool ED_screen_change(struct bContext *C, struct bScreen *screen);
void ED_screen_scene_change(struct bContext *C, struct wmWindow *win, struct Scene *scene);
void ED_screen_scene_change(struct bContext *C,
struct wmWindow *win,
struct Scene *scene,
const bool refresh_toolsystem);
void ED_screen_set_active_region(struct bContext *C, struct wmWindow *win, const int xy[2]);
void ED_screen_exit(struct bContext *C, struct wmWindow *window, struct bScreen *screen);
void ED_screen_animation_timer(struct bContext *C, int redraws, int sync, int enable);

View File

@ -57,6 +57,7 @@
#include "UI_interface.h"
#include "WM_message.h"
#include "WM_toolsystem.h"
#include "DEG_depsgraph_query.h"
@ -1239,7 +1240,10 @@ static void screen_set_3dview_camera(Scene *scene,
}
}
void ED_screen_scene_change(bContext *C, wmWindow *win, Scene *scene)
void ED_screen_scene_change(bContext *C,
wmWindow *win,
Scene *scene,
const bool refresh_toolsystem)
{
#if 0
ViewLayer *view_layer_old = WM_window_get_active_view_layer(win);
@ -1277,6 +1281,10 @@ void ED_screen_scene_change(bContext *C, wmWindow *win, Scene *scene)
}
}
}
if (refresh_toolsystem) {
WM_toolsystem_refresh_screen_window(win);
}
}
ScrArea *ED_screen_full_newspace(bContext *C, ScrArea *area, int type)

View File

@ -134,6 +134,7 @@ void WM_toolsystem_refresh_active(struct bContext *C);
void WM_toolsystem_refresh_screen_area(struct WorkSpace *workspace,
struct ViewLayer *view_layer,
struct ScrArea *area);
void WM_toolsystem_refresh_screen_window(struct wmWindow *win);
void WM_toolsystem_refresh_screen_all(struct Main *bmain);
#ifdef __cplusplus

View File

@ -572,25 +572,29 @@ void WM_toolsystem_refresh_screen_area(WorkSpace *workspace, ViewLayer *view_lay
}
}
void WM_toolsystem_refresh_screen_window(wmWindow *win)
{
WorkSpace *workspace = WM_window_get_active_workspace(win);
bool space_type_has_tools[SPACE_TYPE_LAST + 1] = {0};
LISTBASE_FOREACH (bToolRef *, tref, &workspace->tools) {
space_type_has_tools[tref->space_type] = true;
}
bScreen *screen = WM_window_get_active_screen(win);
ViewLayer *view_layer = WM_window_get_active_view_layer(win);
LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) {
area->runtime.tool = NULL;
area->runtime.is_tool_set = true;
if (space_type_has_tools[area->spacetype]) {
WM_toolsystem_refresh_screen_area(workspace, view_layer, area);
}
}
}
void WM_toolsystem_refresh_screen_all(Main *bmain)
{
/* Update all ScrArea's tools */
for (wmWindowManager *wm = bmain->wm.first; wm; wm = wm->id.next) {
LISTBASE_FOREACH (wmWindow *, win, &wm->windows) {
WorkSpace *workspace = WM_window_get_active_workspace(win);
bool space_type_has_tools[SPACE_TYPE_LAST + 1] = {0};
LISTBASE_FOREACH (bToolRef *, tref, &workspace->tools) {
space_type_has_tools[tref->space_type] = true;
}
bScreen *screen = WM_window_get_active_screen(win);
ViewLayer *view_layer = WM_window_get_active_view_layer(win);
LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) {
area->runtime.tool = NULL;
area->runtime.is_tool_set = true;
if (space_type_has_tools[area->spacetype]) {
WM_toolsystem_refresh_screen_area(workspace, view_layer, area);
}
}
}
}
}

View File

@ -854,7 +854,8 @@ wmWindow *WM_window_open(bContext *C,
/* Set scene and view layer to match original window. */
STRNCPY(win->view_layer_name, view_layer->name);
if (WM_window_get_active_scene(win) != scene) {
ED_screen_scene_change(C, win, scene);
/* No need to refresh the tool-system as the window has not yet finished being setup. */
ED_screen_scene_change(C, win, scene, false);
}
screen->temp = temp;
@ -2271,13 +2272,13 @@ void WM_window_set_active_scene(Main *bmain, bContext *C, wmWindow *win, Scene *
/* Set scene in parent and its child windows. */
if (win_parent->scene != scene) {
ED_screen_scene_change(C, win_parent, scene);
ED_screen_scene_change(C, win_parent, scene, true);
changed = true;
}
LISTBASE_FOREACH (wmWindow *, win_child, &wm->windows) {
if (win_child->parent == win_parent && win_child->scene != scene) {
ED_screen_scene_change(C, win_child, scene);
ED_screen_scene_change(C, win_child, scene, true);
changed = true;
}
}