Fix T42303 Icons lost after loading window
authorAntony Riakiotakis <kalast@gmail.com>
Sun, 19 Oct 2014 18:50:43 +0000 (20:50 +0200)
committerAntony Riakiotakis <kalast@gmail.com>
Sun, 19 Oct 2014 18:50:57 +0000 (20:50 +0200)
The issue here is that if no matching winid is found, we destroy all
windows and their context with them. This will also delete the OpenGL
textures associated with the initial context, thus we lose the icons.
This patch makes sure a window is always kept for later so the initial
context does not get lost.

Thanks to Campbell and Ton for the discussion on the issue.

source/blender/windowmanager/intern/wm_files.c

index 832fef404e3def7bbc69294b4e03315e599c143f..7865e09cbe2e0da381bb9c2403a24e42f82692f3 100644 (file)
@@ -171,6 +171,28 @@ static void wm_window_match_init(bContext *C, ListBase *wmlist)
 #endif
 }
 
+static void wm_window_substitute_old(wmWindowManager *wm, wmWindow *oldwin, wmWindow *win)
+{
+       win->ghostwin = oldwin->ghostwin;
+       win->active = oldwin->active;
+       if (win->active)
+               wm->winactive = win;
+
+       if (!G.background) /* file loading in background mode still calls this */
+               GHOST_SetWindowUserData(win->ghostwin, win);    /* pointer back */
+
+       oldwin->ghostwin = NULL;
+
+       win->eventstate = oldwin->eventstate;
+       oldwin->eventstate = NULL;
+
+       /* ensure proper screen rescaling */
+       win->sizex = oldwin->sizex;
+       win->sizey = oldwin->sizey;
+       win->posx = oldwin->posx;
+       win->posy = oldwin->posy;
+}
+
 /* match old WM with new, 4 cases:
  * 1- no current wm, no read wm: make new default
  * 2- no current wm, but read wm: that's OK, do nothing
@@ -224,6 +246,8 @@ static void wm_window_match_do(bContext *C, ListBase *oldwmlist)
                        ED_screens_initialize(G.main->wm.first);
                }
                else {
+                       bool has_match = false;
+
                        /* what if old was 3, and loaded 1? */
                        /* this code could move to setup_appdata */
                        oldwm = oldwmlist->first;
@@ -243,33 +267,27 @@ static void wm_window_match_do(bContext *C, ListBase *oldwmlist)
                        /* ensure making new keymaps and set space types */
                        wm->initialized = 0;
                        wm->winactive = NULL;
-                       
+
                        /* only first wm in list has ghostwins */
                        for (win = wm->windows.first; win; win = win->next) {
                                for (oldwin = oldwm->windows.first; oldwin; oldwin = oldwin->next) {
-                                       
-                                       if (oldwin->winid == win->winid) {
-                                               win->ghostwin = oldwin->ghostwin;
-                                               win->active = oldwin->active;
-                                               if (win->active)
-                                                       wm->winactive = win;
 
-                                               if (!G.background) /* file loading in background mode still calls this */
-                                                       GHOST_SetWindowUserData(win->ghostwin, win);    /* pointer back */
+                                       if (oldwin->winid == win->winid) {
+                                               has_match = true;
 
-                                               oldwin->ghostwin = NULL;
-                                               
-                                               win->eventstate = oldwin->eventstate;
-                                               oldwin->eventstate = NULL;
-                                               
-                                               /* ensure proper screen rescaling */
-                                               win->sizex = oldwin->sizex;
-                                               win->sizey = oldwin->sizey;
-                                               win->posx = oldwin->posx;
-                                               win->posy = oldwin->posy;
+                                               wm_window_substitute_old(wm, oldwin, win);
                                        }
                                }
                        }
+
+                       /* make sure at least one window is kept open so we don't lose the context, check T42303 */
+                       if (!has_match) {
+                               oldwin = oldwm->windows.first;
+                               win = wm->windows.first;
+
+                               wm_window_substitute_old(wm, oldwin, win);
+                       }
+
                        wm_close_and_free_all(C, oldwmlist);
                }
        }