diff options
author | Campbell Barton <campbell@blender.org> | 2022-05-05 12:51:43 +0300 |
---|---|---|
committer | Campbell Barton <campbell@blender.org> | 2022-05-05 13:13:10 +0300 |
commit | 598917f49b3564c1ca1b28907547332d69a85328 (patch) | |
tree | 932f3b6713855453709516ea344effb3c78d2a63 /source/blender/windowmanager/intern/wm_toolsystem.c | |
parent | 7e02c901031f96380ba63795563d0d36517cafe2 (diff) |
Fix T97874: Python exception after undo with image space visible
Ensure tools are initialized with the correct area type set.
Diffstat (limited to 'source/blender/windowmanager/intern/wm_toolsystem.c')
-rw-r--r-- | source/blender/windowmanager/intern/wm_toolsystem.c | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/source/blender/windowmanager/intern/wm_toolsystem.c b/source/blender/windowmanager/intern/wm_toolsystem.c index e84b6485596..8c7cf86d050 100644 --- a/source/blender/windowmanager/intern/wm_toolsystem.c +++ b/source/blender/windowmanager/intern/wm_toolsystem.c @@ -492,6 +492,14 @@ bool WM_toolsystem_key_from_context(ViewLayer *view_layer, ScrArea *area, bToolK void WM_toolsystem_refresh_active(bContext *C) { Main *bmain = CTX_data_main(C); + + struct { + wmWindow *win; + ScrArea *area; + ARegion *region; + bool is_set; + } context_prev = {0}; + 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); @@ -511,6 +519,16 @@ void WM_toolsystem_refresh_active(bContext *C) }; bToolRef *tref = WM_toolsystem_ref_find(workspace, &tkey); if (tref != area->runtime.tool) { + if (context_prev.is_set == false) { + context_prev.win = CTX_wm_window(C); + context_prev.area = CTX_wm_area(C); + context_prev.region = CTX_wm_region(C); + context_prev.is_set = true; + } + + CTX_wm_window_set(C, win); + CTX_wm_area_set(C, area); + toolsystem_reinit_ensure_toolref(C, workspace, &tkey, NULL); } } @@ -518,6 +536,12 @@ void WM_toolsystem_refresh_active(bContext *C) } } + if (context_prev.is_set) { + CTX_wm_window_set(C, context_prev.win); + CTX_wm_area_set(C, context_prev.area); + CTX_wm_region_set(C, context_prev.region); + } + BKE_workspace_id_tag_all_visible(bmain, LIB_TAG_DOIT); LISTBASE_FOREACH (WorkSpace *, workspace, &bmain->workspaces) { @@ -608,6 +632,16 @@ bToolRef *WM_toolsystem_ref_set_by_id_ex( if (ot == NULL) { return NULL; } + + /* Some contexts use the current space type (image editor for e.g.), + * ensure this is set correctly or there is no area. */ +#ifndef NDEBUG + { + ScrArea *area = CTX_wm_area(C); + BLI_assert(area == NULL || area->spacetype == tkey->space_type); + } +#endif + PointerRNA op_props; WM_operator_properties_create_ptr(&op_props, ot); RNA_string_set(&op_props, "name", name); |