[Bf-blender-cvs] [9cb7ecefcee] master: Fix T73487: Crash when opening filebrowser while error is displayed

Julian Eisel noreply at git.blender.org
Wed Jan 29 15:10:16 CET 2020


Commit: 9cb7ecefceee9f1751c3794d54ad1aa3f477f0aa
Author: Julian Eisel
Date:   Wed Jan 29 15:00:31 2020 +0100
Branches: master
https://developer.blender.org/rB9cb7ecefceee9f1751c3794d54ad1aa3f477f0aa

Fix T73487: Crash when opening filebrowser while error is displayed

More concretly, the crash would happen if a filebrowser is opened while
an error popup is visisble **in a different window**.

Code assumed the popup to be in the active window/screen, but it may
actually be displayed in a non-active window. Temporarily override
context to ensure this assumption is correct.

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

M	source/blender/editors/interface/interface_region_popup.c

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

diff --git a/source/blender/editors/interface/interface_region_popup.c b/source/blender/editors/interface/interface_region_popup.c
index 59d955e0278..867ac652505 100644
--- a/source/blender/editors/interface/interface_region_popup.c
+++ b/source/blender/editors/interface/interface_region_popup.c
@@ -524,20 +524,44 @@ void ui_popup_block_scrolltest(uiBlock *block)
 
 static void ui_popup_block_remove(bContext *C, uiPopupBlockHandle *handle)
 {
-  wmWindow *win = CTX_wm_window(C);
+  wmWindow *ctx_win = CTX_wm_window(C);
+  ScrArea *ctx_sa = CTX_wm_area(C);
+  ARegion *ctx_ar = CTX_wm_region(C);
+
+  wmWindowManager *wm = CTX_wm_manager(C);
+  wmWindow *win = ctx_win;
   bScreen *sc = CTX_wm_screen(C);
 
+  /* There may actually be a different window active than the one showing the popup, so lookup real
+   * one. */
+  if (BLI_findindex(&sc->regionbase, handle->region) == -1) {
+    for (win = wm->windows.first; win; win = win->next) {
+      sc = WM_window_get_active_screen(win);
+      if (BLI_findindex(&sc->regionbase, handle->region) != -1) {
+        break;
+      }
+    }
+  }
+
+  BLI_assert(win && sc);
+
+  CTX_wm_window_set(C, win);
   ui_region_temp_remove(C, sc, handle->region);
 
+  /* Reset context (area and region were NULL'ed when chaning context window). */
+  CTX_wm_window_set(C, ctx_win);
+  CTX_wm_area_set(C, ctx_sa);
+  CTX_wm_region_set(C, ctx_ar);
+
   /* reset to region cursor (only if there's not another menu open) */
   if (BLI_listbase_is_empty(&sc->regionbase)) {
-    ED_region_cursor_set(win, CTX_wm_area(C), CTX_wm_region(C));
+    ED_region_cursor_set(win, ctx_sa, ctx_ar);
     /* in case cursor needs to be changed again */
     WM_event_add_mousemove(C);
   }
 
   if (handle->scrolltimer) {
-    WM_event_remove_timer(CTX_wm_manager(C), win, handle->scrolltimer);
+    WM_event_remove_timer(wm, win, handle->scrolltimer);
   }
 }



More information about the Bf-blender-cvs mailing list