Fix T97874: Python exception after undo with image space visible

Ensure tools are initialized with the correct area type set.
This commit is contained in:
Campbell Barton 2022-05-05 19:51:43 +10:00
parent 7e02c90103
commit 598917f49b
Notes: blender-bot 2023-02-14 06:42:54 +01:00
Referenced by issue #97874, Python exception after undo with image space visible
1 changed files with 34 additions and 0 deletions

View File

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