[Bf-blender-cvs] [598917f49b3] blender-v3.2-release: Fix T97874: Python exception after undo with image space visible

Campbell Barton noreply at git.blender.org
Thu May 5 12:13:47 CEST 2022


Commit: 598917f49b3564c1ca1b28907547332d69a85328
Author: Campbell Barton
Date:   Thu May 5 19:51:43 2022 +1000
Branches: blender-v3.2-release
https://developer.blender.org/rB598917f49b3564c1ca1b28907547332d69a85328

Fix T97874: Python exception after undo with image space visible

Ensure tools are initialized with the correct area type set.

===================================================================

M	source/blender/windowmanager/intern/wm_toolsystem.c

===================================================================

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



More information about the Bf-blender-cvs mailing list