Fix crash closing stacked file browser window
authorJulian Eisel <eiseljulian@gmail.com>
Sat, 7 Sep 2019 20:40:28 +0000 (22:40 +0200)
committerJulian Eisel <eiseljulian@gmail.com>
Sun, 8 Sep 2019 12:37:12 +0000 (14:37 +0200)
Caused by ab823176d31dc1.
Steps to reproduce were:
* Open Preferences
* Open file browser through Lights -> Install (doesn't matter which)
* Close browser through the window controlls

The window was freed earlier, but still referenced by new handler
context storage.

source/blender/windowmanager/intern/wm_event_system.c

index ff22956e7235c0a3326006bbd5a5bde96b68b057..21c6c2ae60bcedd6094bbeeddc6a35baeb1e9fb1 100644 (file)
@@ -2384,7 +2384,13 @@ static int wm_handler_fileselect_do(bContext *C,
       /* remlink now, for load file case before removing*/
       BLI_remlink(handlers, handler);
 
-      if (val != EVT_FILESELECT_EXTERNAL_CANCEL) {
+      if (val == EVT_FILESELECT_EXTERNAL_CANCEL) {
+        /* The window might have been freed already. */
+        if (BLI_findindex(&wm->windows, handler->context.win) == -1) {
+          handler->context.win = NULL;
+        }
+      }
+      else {
         for (wmWindow *win = wm->windows.first; win; win = win->next) {
           if (WM_window_is_temp_screen(win)) {
             bScreen *screen = WM_window_get_active_screen(win);