[#20112] User Preferences window causes a crash
authorMartin Poirier <theeth@yahoo.com>
Wed, 13 Jan 2010 21:37:13 +0000 (21:37 +0000)
committerMartin Poirier <theeth@yahoo.com>
Wed, 13 Jan 2010 21:37:13 +0000 (21:37 +0000)
Opened preference window caused a crash (context pointing to freed screen) when Load UI was turned off.

source/blender/editors/screen/screen_edit.c
source/blender/windowmanager/intern/wm_files.c

index 2069858..20c629a 100644 (file)
@@ -1125,7 +1125,13 @@ void ED_screen_exit(bContext *C, wmWindow *window, bScreen *screen)
        screen->winid= 0;
        
        /* before deleting the temp screen or we get invalid access */
-       CTX_wm_window_set(C, prevwin);
+       if (prevwin->screen->full != SCREENTEMP) {
+               /* use previous window if possible */
+               CTX_wm_window_set(C, prevwin);
+       } else {
+               /* none otherwise */
+               CTX_wm_window_set(C, NULL);
+       }
        
        /* if temp screen, delete it */
        if(screen->full == SCREENTEMP) {
index 05fdb50..6f44ce8 100644 (file)
@@ -109,11 +109,13 @@ static void writeBlog(void);
 static void wm_window_match_init(bContext *C, ListBase *wmlist)
 {
        wmWindowManager *wm= G.main->wm.first;
-       wmWindow *win;
+       wmWindow *win, *active_win;
        
        *wmlist= G.main->wm;
        G.main->wm.first= G.main->wm.last= NULL;
        
+       active_win = CTX_wm_window(C);
+
        /* first wrap up running stuff */
        /* code copied from wm_init_exit.c */
        for(wm= wmlist->first; wm; wm= wm->id.next) {
@@ -129,6 +131,9 @@ static void wm_window_match_init(bContext *C, ListBase *wmlist)
                }
        }
        
+       /* reset active window */
+       CTX_wm_window_set(C, active_win);
+
        ED_editors_exit(C);
        
 return;