Bugfix #20812 (and probably others)
authorTon Roosendaal <ton@blender.org>
Tue, 9 Nov 2010 14:54:59 +0000 (14:54 +0000)
committerTon Roosendaal <ton@blender.org>
Tue, 9 Nov 2010 14:54:59 +0000 (14:54 +0000)
Issue: in user preferences window, using file selecting caused the
the userpref window to be saved, and not closing.

Reason: design error (by me) in using screen->full tag for denoting
a temporarily screen (like file window). Fixed by using a new
screen->temp variable for it.

System remained unstable though, noticed another issue with freeing
temp screens in wrong places. Seems nice stable now! Will check on
the wiki for relarted issues now.

source/blender/blenloader/intern/readfile.c
source/blender/editors/render/render_internal.c
source/blender/editors/screen/screen_edit.c
source/blender/editors/screen/screen_ops.c
source/blender/makesdna/DNA_screen_types.h
source/blender/windowmanager/intern/wm_files.c
source/blender/windowmanager/intern/wm_window.c

index 36d2be69941a8ff0a466158b2fafefe9b4e5e823..131d080d2c8717cae8e1860bc5a2b02117b14cee 100644 (file)
@@ -10344,31 +10344,6 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
                                }
                        }
                }
-               /* clear hanging 'temp' screens from older 2.5 files*/
-               if (main->versionfile == 250) {
-                       bScreen *screen, *nextscreen;
-                       wmWindowManager *wm;
-                       wmWindow *win, *nextwin;
-
-                       for(screen= main->screen.first; screen; screen= nextscreen) {
-                               nextscreen= screen->id.next;
-
-                               if (screen->full == SCREENTEMP) {
-                                       /* remove corresponding windows */
-                                       for(wm= main->wm.first; wm; wm=wm->id.next) {
-                                               for(win= wm->windows.first; win; win=nextwin) {
-                                                       nextwin= win->next;
-
-                                                       if(newlibadr(fd, wm->id.lib, win->screen) == screen)
-                                                               BLI_freelinkN(&wm->windows, win);
-                                               }
-                                       }
-
-                                       /* remove screen itself */
-                                       free_libblock(&main->screen, screen);
-                               }
-                       }
-               }
        }
        
        if (main->versionfile < 250 || (main->versionfile == 250 && main->subversionfile < 9))
index dee46ba42a7147e1f41bff23e0639881fbcf27ba..2bb76a8d173a007b51c2712af4352c0c0f2269ac 100644 (file)
@@ -781,7 +781,7 @@ static int render_view_cancel_exec(bContext *C, wmOperator *UNUSED(unused))
        SpaceImage *sima= sa->spacedata.first;
 
        /* test if we have a temp screen in front */
-       if(CTX_wm_window(C)->screen->full==SCREENTEMP) {
+       if(CTX_wm_window(C)->screen->temp) {
                wm_window_lower(CTX_wm_window(C));
                return OPERATOR_FINISHED;
        }
@@ -826,7 +826,7 @@ static int render_view_show_invoke(bContext *C, wmOperator *UNUSED(unused), wmEv
        ScrArea *sa= find_area_showing_r_result(C);
 
        /* test if we have a temp screen in front */
-       if(CTX_wm_window(C)->screen->full==SCREENTEMP) {
+       if(CTX_wm_window(C)->screen->temp) {
                wm_window_lower(CTX_wm_window(C));
        }
        /* determine if render already shows */
index e3da9af4e2de9f2f8d06093aa9a4eccef54d65f7..130916f4285e17a47380f7e584ef848ef28dd375 100644 (file)
@@ -1140,8 +1140,7 @@ void ED_screen_exit(bContext *C, wmWindow *window, bScreen *screen)
        /* mark it available for use for other windows */
        screen->winid= 0;
        
-       /* before deleting the temp screen or we get invalid access */
-       if (prevwin->screen->full != SCREENTEMP) {
+       if (prevwin->screen->temp == 0) {
                /* use previous window if possible */
                CTX_wm_window_set(C, prevwin);
        } else {
@@ -1149,11 +1148,6 @@ void ED_screen_exit(bContext *C, wmWindow *window, bScreen *screen)
                CTX_wm_window_set(C, NULL);
        }
        
-       /* if temp screen, delete it */
-       if(screen->full == SCREENTEMP) {
-               Main *bmain= CTX_data_main(C);
-               free_libblock(&bmain->screen, screen);
-       }
 }
 
 /* *********************************** */
@@ -1560,46 +1554,39 @@ ScrArea *ED_screen_full_toggle(bContext *C, wmWindow *win, ScrArea *sa)
        }
 
        if(sa && sa->full) {
+               ScrArea *old;
                short fulltype;
 
                sc= sa->full;           /* the old screen to restore */
                oldscreen= win->screen; /* the one disappearing */
 
                fulltype = sc->full;
+               sc->full= 0;
 
-               /* refuse to go out of SCREENAUTOPLAY as long as G_FLAGS_AUTOPLAY
-                  is set */
-
-               if (fulltype != SCREENAUTOPLAY || (G.flags & G_FILE_AUTOPLAY) == 0) {
-                       ScrArea *old;
+               /* removed: SCREENAUTOPLAY exception here */
+       
+               /* find old area */
+               for(old= sc->areabase.first; old; old= old->next)
+                       if(old->full) break;
+               if(old==NULL) {
+                       if (G.f & G_DEBUG)
+                               printf("something wrong in areafullscreen\n");
+                       return NULL;
+               }
 
-                       sc->full= 0;
+               area_copy_data(old, sa, 1);     /*  1 = swap spacelist */
+               if (sa->flag & AREA_TEMP_INFO) sa->flag &= ~AREA_TEMP_INFO;
+               old->full= NULL;
 
-                       /* find old area */
-                       for(old= sc->areabase.first; old; old= old->next)
-                               if(old->full) break;
-                       if(old==NULL) {
-                               if (G.f & G_DEBUG)
-                                       printf("something wrong in areafullscreen\n");
-                               return NULL;
-                       }
-                               // old feature described below (ton)
-                               // in autoplay screens the headers are disabled by
-                               // default. So use the old headertype instead
-
-                       area_copy_data(old, sa, 1);     /*  1 = swap spacelist */
-                       if (sa->flag & AREA_TEMP_INFO) sa->flag &= ~AREA_TEMP_INFO;
-                       old->full= NULL;
+               /* animtimer back */
+               sc->animtimer= oldscreen->animtimer;
+               oldscreen->animtimer= NULL;
 
-                       /* animtimer back */
-                       sc->animtimer= oldscreen->animtimer;
-                       oldscreen->animtimer= NULL;
+               ED_screen_set(C, sc);
 
-                       ED_screen_set(C, sc);
+               free_screen(oldscreen);
+               free_libblock(&CTX_data_main(C)->screen, oldscreen);
 
-                       free_screen(oldscreen);
-                       free_libblock(&CTX_data_main(C)->screen, oldscreen);
-               }
        }
        else {
                ScrArea *newa;
@@ -1614,7 +1601,7 @@ ScrArea *ED_screen_full_toggle(bContext *C, wmWindow *win, ScrArea *sa)
                */
 
                oldscreen->full = SCREENFULL;
-               BLI_snprintf(newname, sizeof(newname), "%s-%s", oldscreen->id.name+2, "temp");
+               BLI_snprintf(newname, sizeof(newname), "%s-%s", oldscreen->id.name+2, "full");
                sc= ED_screen_add(win, oldscreen->scene, newname);
                sc->full = SCREENFULL; // XXX
 
index 7cdd19e435b7faa67105631afc4c6e5e6ed1de7f..1c47065ac76afa76aef4ddb7d801a8cc2349ff12 100644 (file)
@@ -1708,6 +1708,10 @@ static int screen_set_exec(bContext *C, wmOperator *op)
        int tot= BLI_countlist(&CTX_data_main(C)->screen);
        int delta= RNA_int_get(op->ptr, "delta");
        
+       /* temp screens are for userpref or render display */
+       if(screen->temp)
+               return OPERATOR_CANCELLED;
+       
        /* return to previous state before switching screens */
        if(sa && sa->full)
                ED_screen_full_restore(C, sa);
@@ -2817,7 +2821,6 @@ static void SCREEN_OT_back_to_previous(struct wmOperatorType *ot)
 
 static int userpref_show_invoke(bContext *C, wmOperator *UNUSED(op), wmEvent *event)
 {
-       ScrArea *sa;
        rcti rect;
        int sizex, sizey;
        
@@ -2833,9 +2836,6 @@ static int userpref_show_invoke(bContext *C, wmOperator *UNUSED(op), wmEvent *ev
        /* changes context! */
        WM_window_open_temp(C, &rect, WM_WINDOW_USERPREFS);
        
-       sa= CTX_wm_area(C);
-       
-       
        return OPERATOR_FINISHED;
 }
 
index a811fd9c014724854808e5c694035fccf7224d4b..7091bc79a5bccfd1dd62ab8d45283b0fc3cb2f06 100644 (file)
@@ -54,7 +54,8 @@ typedef struct bScreen {
        struct Scene *scene;
        struct Scene *newscene;                         /* temporary when switching */
        
-       short full;                                                     /* fade out? */
+       short full;                                                     /* temp screen for image render display or fileselect */
+       short temp;                                                     /* temp screen in a temp window, don't save (like user prefs) */
        short winid;                                            /* winid from WM, starts with 1 */
        short do_draw;                                          /* notifier for drawing edges */
        short do_refresh;                                       /* notifier for scale screen, changed screen, etc */
@@ -66,7 +67,7 @@ typedef struct bScreen {
        short mainwin;                                          /* screensize subwindow, for screenedges and global menus */
        short subwinactive;                                     /* active subwindow */
        
-       int pad2;
+       short pad;
        
        struct wmTimer *animtimer;                      /* if set, screen has timer handler added in window */
        void *context;                                          /* context callback */
@@ -187,10 +188,9 @@ typedef struct ARegion {
 #define HEADERDOWN     1
 #define HEADERTOP      2
 
+/* screen->full */
 #define SCREENNORMAL    0
 #define SCREENFULL      1
-#define SCREENAUTOPLAY  2
-#define SCREENTEMP             3
 
 
 /* Panel->snap - for snapping to screen edges */
index ca37f0db61b4eddb10f41d559ce0bcf98d3f2b1e..2dbcb92e13d3879981c666808e685db0f088b0a1 100644 (file)
@@ -673,7 +673,7 @@ int WM_write_homefile(bContext *C, wmOperator *op)
        int fileflags;
        
        /* check current window and close it if temp */
-       if(win->screen->full == SCREENTEMP)
+       if(win->screen->temp)
                wm_window_close(C, wm, win);
        
        BLI_make_file_string("/", tstr, BLI_get_folder_create(BLENDER_USER_CONFIG, NULL), BLENDER_STARTUP_FILE);
index 35a3fbcf9fb31ff87413a839c3db5481b117d894..315f7edf1ec2ccca49e4fa60bc2759b1856e8f5b 100644 (file)
@@ -44,6 +44,7 @@
 
 #include "BKE_blender.h"
 #include "BKE_context.h"
+#include "BKE_library.h"
 #include "BKE_global.h"
 #include "BKE_main.h"
 #include "BKE_utildefines.h"
@@ -237,13 +238,20 @@ void wm_window_close(bContext *C, wmWindowManager *wm, wmWindow *win)
        CTX_wm_window_set(C, win);      /* needed by handlers */
        WM_event_remove_handlers(C, &win->handlers);
        WM_event_remove_handlers(C, &win->modalhandlers);
-       ED_screen_exit(C, win, win->screen); /* will free the current screen if it is a temp layout */
+       ED_screen_exit(C, win, win->screen); 
+       
+       /* if temp screen, delete it */
+       if(win->screen->temp) {
+               Main *bmain= CTX_data_main(C);
+               free_libblock(&bmain->screen, win->screen);
+       }
+       
        wm_window_free(C, wm, win);
        
        /* check remaining windows */
        if(wm->windows.first) {
                for(win= wm->windows.first; win; win= win->next)
-                       if(win->screen->full!=SCREENTEMP)
+                       if(win->screen->temp == 0)
                                break;
                /* in this case we close all */
                if(win==NULL)
@@ -256,7 +264,7 @@ void wm_window_close(bContext *C, wmWindowManager *wm, wmWindow *win)
 void wm_window_title(wmWindowManager *wm, wmWindow *win)
 {
        /* handle the 'temp' window */
-       if(win->screen && win->screen->full==SCREENTEMP) {
+       if(win->screen && win->screen->temp) {
                GHOST_SetTitle(win->ghostwin, "Blender");
        }
        else {
@@ -430,7 +438,7 @@ wmWindow *WM_window_open(bContext *C, rcti *rect)
        return win;
 }
 
-/* uses screen->full tag to define what to do, currently it limits
+/* uses screen->temp tag to define what to do, currently it limits
    to only one "temp" window for render out, preferences, filewindow, etc */
 /* type is #define in WM_api.h */
 
@@ -444,7 +452,7 @@ void WM_window_open_temp(bContext *C, rcti *position, int type)
        
        /* test if we have a temp screen already */
        for(win= CTX_wm_manager(C)->windows.first; win; win= win->next)
-               if(win->screen->full == SCREENTEMP)
+               if(win->screen->temp)
                        break;
        
        /* add new window? */
@@ -466,7 +474,7 @@ void WM_window_open_temp(bContext *C, rcti *position, int type)
        /* add new screen? */
        if(win->screen==NULL)
                win->screen= ED_screen_add(win, CTX_data_scene(C), "temp");
-       win->screen->full = SCREENTEMP
+       win->screen->temp = 1
        
        /* make window active, and validate/resize */
        CTX_wm_window_set(C, win);