commit before doing some hefty shapekey change, will break compilation
[blender-staging.git] / source / blender / windowmanager / intern / wm_init_exit.c
index aaa38cee7d8e300382fb1ccfb2ec5f6684b1102e..b24ad19649de376c93cd8cf1b3b9bdd53ef858de 100644 (file)
@@ -55,6 +55,7 @@
 #include "BKE_packedFile.h"
 
 #include "BLI_blenlib.h"
+#include "BLI_cellalloc.h"
 
 #include "RE_pipeline.h"               /* RE_ free stuff */
 
@@ -78,7 +79,7 @@
 #include "ED_armature.h"
 #include "ED_keyframing.h"
 #include "ED_node.h"
-#include "ED_previewrender.h"
+#include "ED_render.h"
 #include "ED_space_api.h"
 #include "ED_screen.h"
 #include "ED_util.h"
 #include "UI_interface.h"
 #include "BLF_api.h"
 
+#include "gpu_buffers.h"
 #include "GPU_extensions.h"
 #include "GPU_draw.h"
 
+#include "BKE_depsgraph.h"
 #include "BKE_sound.h"
 
 static void wm_init_reports(bContext *C)
@@ -112,6 +115,7 @@ void WM_init(bContext *C)
        
        set_free_windowmanager_cb(wm_close_and_free);   /* library.c */
        set_blender_test_break_cb(wm_window_testbreak); /* blender.c */
+       DAG_editors_update_cb(ED_render_id_flush_update); /* depsgraph.c */
        
        ED_spacetypes_init();   /* editors/space_api/spacetype.c */
        
@@ -128,6 +132,8 @@ void WM_init(bContext *C)
        
        wm_init_reports(C); /* reports cant be initialized before the wm */
        
+       GPU_extensions_init();
+
        UI_init();
        
        //      clear_matcopybuf(); /* XXX */
@@ -138,14 +144,10 @@ void WM_init(bContext *C)
        
        ED_preview_init_dbase();
        
-       GPU_extensions_init();
-       
        G.ndofdevice = -1;      /* XXX bad initializer, needs set otherwise buttons show! */
        
        read_Blog();
        BLI_strncpy(G.lib, G.sce, FILE_MAX);
-
-       sound_init();
 }
 
 /* free strings of open recent files */
@@ -168,6 +170,7 @@ extern wchar_t *copybufinfo;
 
        // XXX copy/paste buffer stuff...
 extern void free_anim_copybuf(); 
+extern void free_anim_drivers_copybuf(); 
 extern void free_posebuf(); 
 
 /* called in creator.c even... tsk, split this! */
@@ -188,10 +191,12 @@ void WM_exit(bContext *C)
                        
                        CTX_wm_window_set(C, win);      /* needed by operator close callbacks */
                        WM_event_remove_handlers(C, &win->handlers);
+                       WM_event_remove_handlers(C, &win->modalhandlers);
                        ED_screen_exit(C, win, win->screen);
                }
        }
        wm_operatortype_free();
+       WM_menutype_free();
        
        /* all non-screen and non-space stuff editors did, like editmode */
        if(C)
@@ -208,12 +213,6 @@ void WM_exit(bContext *C)
        
        BKE_freecubetable();
        
-       /* before free_blender so py's gc happens while library still exists */
-       /* needed at least for a rare sigsegv that can happen in pydrivers */
-#ifndef DISABLE_PYTHON
-       BPY_end_python();
-#endif
-       
        fastshade_free_render();        /* shaded view */
        ED_preview_free_dbase();        /* frees a Main dbase, before free_blender! */
 
@@ -223,6 +222,7 @@ void WM_exit(bContext *C)
        free_blender();                         /* blender.c, does entire library and spacetypes */
 //     free_matcopybuf();
        free_anim_copybuf();
+       free_anim_drivers_copybuf();
        free_posebuf();
 //     free_vertexpaint();
 //     free_imagepaint();
@@ -236,6 +236,18 @@ void WM_exit(bContext *C)
        
 //     free_txt_data();
        
+
+#ifndef DISABLE_PYTHON
+       /* XXX - old note */
+       /* before free_blender so py's gc happens while library still exists */
+       /* needed at least for a rare sigsegv that can happen in pydrivers */
+
+       /* Update for blender 2.5, move after free_blender because blender now holds references to PyObject's
+        * so decref'ing them after python ends causes bad problems every time
+        * the pyDriver bug can be fixed if it happens again we can deal with it then */
+       BPY_end_python();
+#endif
+
        libtiff_exit();
        
 #ifdef WITH_QUICKTIME
@@ -246,6 +258,7 @@ void WM_exit(bContext *C)
 // XXX         UI_filelist_free_icons();
        }
        
+       GPU_buffer_pool_free(0);
        GPU_extensions_exit();
        
 //     if (copybuf) MEM_freeN(copybuf);
@@ -259,17 +272,22 @@ void WM_exit(bContext *C)
        UI_exit();
        BKE_userdef_free();
 
-       RNA_exit();
+       RNA_exit(); /* should be after BPY_end_python so struct python slots are cleared */
        
        wm_ghost_exit();
 
        CTX_free(C);
        
-       if(MEM_get_memory_blocks_in_use()!=0) {
-               printf("Error Totblock: %d\n", MEM_get_memory_blocks_in_use());
+       SYS_DeleteSystem(SYS_GetSystem());
+
+       if(MEM_get_memory_blocks_in_use()!=0 || BLI_cellalloc_get_totblock()!=0) {
+               printf("Error Totblock: %d\n", 
+                       BLI_cellalloc_get_totblock()+MEM_get_memory_blocks_in_use());
+               BLI_cellalloc_printleaks();
+               BLI_cellalloc_destroy();
                MEM_printmemlist();
        }
-//     delete_autosave();
+       wm_autosave_delete();
        
        printf("\nBlender quit\n");
        
@@ -281,9 +299,6 @@ void WM_exit(bContext *C)
        }
 #endif 
        
-       
-       SYS_DeleteSystem(SYS_GetSystem());
-       
        exit(G.afbreek==1);
 }