2.5
authorTon Roosendaal <ton@blender.org>
Fri, 23 Jan 2009 17:42:36 +0000 (17:42 +0000)
committerTon Roosendaal <ton@blender.org>
Fri, 23 Jan 2009 17:42:36 +0000 (17:42 +0000)
File reading of 2.50 files fixed.
- it now exits nicely from queues without using free'd memory
  (checks CTX_wm_window(C) to be NULL)
- code that matched current (ghost) window with new situation
  lacked setting a pointer good.

Overall cleaned some parts too; like context clears now all
wm related pointers when you set a new wm, window or area.

source/blender/blenkernel/intern/context.c
source/blender/windowmanager/intern/wm.c
source/blender/windowmanager/intern/wm_event_system.c
source/blender/windowmanager/intern/wm_files.c
source/blender/windowmanager/intern/wm_init_exit.c
source/blender/windowmanager/intern/wm_window.c

index 81712acee5c574caf453f812924d2dc0ec8435e2..2a24e5a9d0fd6df2991c494a8a27e949503954d6 100644 (file)
@@ -197,6 +197,10 @@ struct uiBlock *CTX_wm_ui_block(const bContext *C)
 void CTX_wm_manager_set(bContext *C, wmWindowManager *wm)
 {
        C->wm.manager= wm;
+       C->wm.window= NULL;
+       C->wm.screen= NULL;
+       C->wm.area= NULL;
+       C->wm.region= NULL;
 }
 
 void CTX_wm_window_set(bContext *C, wmWindow *win)
@@ -204,17 +208,22 @@ void CTX_wm_window_set(bContext *C, wmWindow *win)
        C->wm.window= win;
        C->wm.screen= (win)? win->screen: NULL;
        C->data.scene= (C->wm.screen)? C->wm.screen->scene: NULL;
+       C->wm.area= NULL;
+       C->wm.region= NULL;
 }
 
 void CTX_wm_screen_set(bContext *C, bScreen *screen)
 {
        C->wm.screen= screen;
        C->data.scene= (C->wm.screen)? C->wm.screen->scene: NULL;
+       C->wm.area= NULL;
+       C->wm.region= NULL;
 }
 
 void CTX_wm_area_set(bContext *C, ScrArea *area)
 {
        C->wm.area= area;
+       C->wm.region= NULL;
 }
 
 void CTX_wm_region_set(bContext *C, ARegion *region)
index 164a49ac63dc46e8d55d0fbf23d61c5496664cee..d264b09601281030e6c7550169db8db1d0fd3448 100644 (file)
@@ -100,7 +100,7 @@ void wm_check(bContext *C)
        wmWindowManager *wm= CTX_wm_manager(C);
        
        /* wm context */
-       if(CTX_wm_manager(C)==NULL) {
+       if(wm==NULL) {
                wm= CTX_data_main(C)->wm.first;
                CTX_wm_manager_set(C, wm);
        }
@@ -118,6 +118,8 @@ void wm_check(bContext *C)
                
                ED_screens_initialize(wm);
                wm->initialized= 1;
+               
+               WM_event_add_notifier(C, NC_WINDOW, NULL);
        }
 }
 
index 0746322e336a7380b3a9b736c0964b1200ade76a..344cd73b727cbe56a3561eb2351a2412e7be5a0b 100644 (file)
@@ -135,6 +135,9 @@ void wm_event_do_notifiers(bContext *C)
        wmNotifier *note;
        wmWindow *win;
        
+       if(wm==NULL)
+               return;
+       
        /* cache & catch WM level notifiers, such as frame change */
        /* XXX todo, multiwindow scenes */
        for(win= wm->windows.first; win; win= win->next) {
@@ -194,7 +197,6 @@ void wm_event_do_notifiers(bContext *C)
                                ED_area_do_refresh(C, sa);
                        }
                }
-               CTX_wm_area_set(C, NULL);
        }
        CTX_wm_window_set(C, NULL);
 }
@@ -686,6 +688,9 @@ static int wm_handlers_do(bContext *C, wmEvent *event, ListBase *handlers)
                                break;
                }
                
+               /* fileread case */
+               if(CTX_wm_window(C)==NULL)
+                       break;
        }
        return action;
 }
@@ -794,6 +799,12 @@ void wm_event_do_handlers(bContext *C)
                        
                        action= wm_handlers_do(C, event, &win->handlers);
                        
+                       /* fileread case */
+                       if(CTX_wm_window(C)==NULL) {
+                               wm_event_free(event);
+                               break;
+                       }
+                       
                        if(wm_event_always_pass(event) || action==WM_HANDLER_CONTINUE) {
                                ScrArea *sa;
                                ARegion *ar;
@@ -843,6 +854,10 @@ void wm_event_do_handlers(bContext *C)
                        CTX_wm_area_set(C, NULL);
                        CTX_wm_region_set(C, NULL);
                }
+               
+               /* fileread case */
+               if(CTX_wm_window(C)==NULL)
+                       break;
        }
 }
 
@@ -867,12 +882,12 @@ wmEventHandler *WM_event_add_modal_handler(bContext *C, ListBase *handlers, wmOp
 wmEventHandler *WM_event_add_keymap_handler(ListBase *handlers, ListBase *keymap)
 {
        wmEventHandler *handler;
-       
+
        /* only allow same keymap once */
        for(handler= handlers->first; handler; handler= handler->next)
                if(handler->keymap==keymap)
                        return handler;
-
+       
        handler= MEM_callocN(sizeof(wmEventHandler), "event keymap handler");
        BLI_addtail(handlers, handler);
        handler->keymap= keymap;
@@ -897,9 +912,11 @@ wmEventHandler *WM_event_add_keymap_handler_priority(ListBase *handlers, ListBas
 wmEventHandler *WM_event_add_keymap_handler_bb(ListBase *handlers, ListBase *keymap, rcti *bblocal, rcti *bbwin)
 {
        wmEventHandler *handler= WM_event_add_keymap_handler(handlers, keymap);
-       handler->bblocal= bblocal;
-       handler->bbwin= bbwin;
        
+       if(handler) {
+               handler->bblocal= bblocal;
+               handler->bbwin= bbwin;
+       }
        return handler;
 }
 
index 684f133c9730fa78313ea134899144fa6b1a967f..20258f3f2d30481be667e8c4e4a9080ac6a3472b 100644 (file)
@@ -78,6 +78,8 @@
 #include "ED_screen.h"
 #include "ED_util.h"
 
+#include "GHOST_C-api.h"
+
 #include "UI_interface.h"
 
 // XXX #include "BPY_extern.h"
@@ -462,7 +464,11 @@ static void wm_window_match_do(bContext *C, ListBase *oldwmlist)
                                        
                                        if(oldwin->winid == win->winid ) {
                                                win->ghostwin= oldwin->ghostwin;
+                                               GHOST_SetWindowUserData(win->ghostwin, win);    /* pointer back */
                                                oldwin->ghostwin= NULL;
+                                               
+                                               win->eventstate= oldwin->eventstate;
+                                               oldwin->eventstate= NULL;
                                        }
                                }
                        }
@@ -492,6 +498,7 @@ void WM_read_file(bContext *C, char *name, ReportList *reports)
 
                /* match the read WM with current WM */
                wm_window_match_do(C, &wmbase); 
+               wm_check(C); /* opens window(s), checks keymaps */
                
 // XXX         mainwindow_set_filename_to_title(G.main->name);
 //             countall(); <-- will be listener
@@ -549,7 +556,8 @@ int WM_read_homefile(bContext *C, int from_memory)
        
        /* match the read WM with current WM */
        wm_window_match_do(C, &wmbase); 
-       
+       wm_check(C); /* opens window(s), checks keymaps */
+
        strcpy(G.sce, scestr); /* restore */
 
        init_userdef_themes();
index dc36cf2d62c6b58144149932bc3b78644305d52b..01e4cd10b3d94cb1c71a3e5bab7407740140a127 100644 (file)
 #include "GPU_draw.h"
 
 
-static void initbuttons(void)
-{
-       UI_init();
-       
-//     glClearColor(.7f, .7f, .6f, 0.0);
-       
-       G.font= BMF_GetFont(BMF_kHelvetica12);
-       G.fonts= BMF_GetFont(BMF_kHelvetica10);
-       G.fontss= BMF_GetFont(BMF_kHelveticaBold8);
-       
-//     clear_matcopybuf(); /* XXX */
-       
-//     glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
-}
 
 /* XXX */
 static void sound_init_listener(void)
@@ -135,11 +121,17 @@ void WM_init(bContext *C)
        /* get the default database, plus a wm */
        WM_read_homefile(C, 0);
        
-       wm_check(C); /* opens window(s), checks keymaps */
+       UI_init();
+       
+       /* goes away */
+       G.font= BMF_GetFont(BMF_kHelvetica12);
+       G.fonts= BMF_GetFont(BMF_kHelvetica10);
+       G.fontss= BMF_GetFont(BMF_kHelveticaBold8);
+       
+       //      clear_matcopybuf(); /* XXX */
+       
+       //      glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
        
-//     initscreen();   /* for (visual) speed, this first, then setscreen */
-       initbuttons();
-//     InitCursorData();
        sound_init_listener();
 //     init_node_butfuncs();
        
index 130d72dffd83fed4cd59b7764a3d5883c94b9a38..06ec8f6819ac057417c72fdf0d4993ba526d90ef 100644 (file)
@@ -102,6 +102,8 @@ void wm_window_free(bContext *C, wmWindow *win)
                        wm->winactive= NULL;
                if(CTX_wm_window(C)==win)
                        CTX_wm_window_set(C, NULL);
+               
+               WM_event_remove_handlers(C, &win->handlers);
        }       
        
        if(win->eventstate) MEM_freeN(win->eventstate);
@@ -160,14 +162,13 @@ wmWindow *wm_window_copy(bContext *C, wmWindow *winorig)
        return win;
 }
 
-/* this is event from ghost */
+/* this is event from ghost, or exit-blender op */
 static void wm_window_close(bContext *C, wmWindow *win)
 {
        wmWindowManager *wm= CTX_wm_manager(C);
        BLI_remlink(&wm->windows, win);
        
        wm_draw_window_clear(win);
-       WM_event_remove_handlers(C, &win->handlers);
        ED_screen_exit(C, win, win->screen);
        wm_window_free(C, win);
        
@@ -203,7 +204,6 @@ static void wm_window_add_ghostwindow(wmWindowManager *wm, char *title, wmWindow
                                                                 0 /* no stereo */);
        
        if (ghostwin) {
-               ListBase *keymap;
                
                win->ghostwin= ghostwin;
                GHOST_SetWindowUserData(ghostwin, win); /* pointer back */
@@ -211,13 +211,6 @@ static void wm_window_add_ghostwindow(wmWindowManager *wm, char *title, wmWindow
                if(win->eventstate==NULL)
                        win->eventstate= MEM_callocN(sizeof(wmEvent), "window event state");
                
-               /* add keymap handlers (1 handler for all keys in map!) */
-               keymap= WM_keymap_listbase(wm, "Window", 0, 0);
-               WM_event_add_keymap_handler(&win->handlers, keymap);
-
-               keymap= WM_keymap_listbase(wm, "Screen", 0, 0);
-               WM_event_add_keymap_handler(&win->handlers, keymap);
-               
                /* until screens get drawn, make it nice grey */
                glClearColor(.55, .55, .55, 0.0);
                glClear(GL_COLOR_BUFFER_BIT);
@@ -232,8 +225,10 @@ static void wm_window_add_ghostwindow(wmWindowManager *wm, char *title, wmWindow
 
 /* for wmWindows without ghostwin, open these and clear */
 /* window size is read from window, if 0 it uses prefsize */
+/* called in wm_check, also inits stuff after file read */
 void wm_window_add_ghostwindows(wmWindowManager *wm)
 {
+       ListBase *keymap;
        wmWindow *win;
        
        /* no commandline prefsize? then we set this */
@@ -264,6 +259,18 @@ void wm_window_add_ghostwindows(wmWindowManager *wm)
                        }
                        wm_window_add_ghostwindow(wm, "Blender", win);
                }
+               /* happens after fileread */
+               if(win->eventstate==NULL)
+                  win->eventstate= MEM_callocN(sizeof(wmEvent), "window event state");
+               
+               
+               /* add keymap handlers (1 handler for all keys in map!) */
+               keymap= WM_keymap_listbase(wm, "Window", 0, 0);
+               WM_event_add_keymap_handler(&win->handlers, keymap);
+               
+               keymap= WM_keymap_listbase(wm, "Screen", 0, 0);
+               WM_event_add_keymap_handler(&win->handlers, keymap);
+               
        }
 }