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.
This commit is contained in:
Julian Eisel 2020-01-29 15:00:31 +01:00
parent fee7a34575
commit 9cb7ecefce

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