commit before doing some hefty shapekey change, will break compilation
[blender-staging.git] / source / blender / windowmanager / intern / wm_init_exit.c
index 64d61210c14a5f70c8248f569256f13fd0ab018a..b24ad19649de376c93cd8cf1b3b9bdd53ef858de 100644 (file)
@@ -38,7 +38,6 @@
 
 #include "DNA_object_types.h"
 #include "DNA_scene_types.h"
-#include "DNA_sound_types.h"
 #include "DNA_userdef_types.h"
 #include "DNA_windowmanager_types.h"
 
 #include "BKE_global.h"
 #include "BKE_library.h"
 #include "BKE_mball.h"
+#include "BKE_report.h"
 #include "BKE_utildefines.h"
 #include "BKE_packedFile.h"
 
-#include "BMF_Api.h"
-
 #include "BLI_blenlib.h"
+#include "BLI_cellalloc.h"
 
 #include "RE_pipeline.h"               /* RE_ free stuff */
 
-#include "radio.h"
-
 #ifndef DISABLE_PYTHON
 #include "BPY_extern.h"
 #endif
@@ -82,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"
 
-
-/* XXX */
-static void sound_init_listener(void)
+static void wm_init_reports(bContext *C)
 {
-       G.listener = MEM_callocN(sizeof(bSoundListener), "soundlistener");
-       G.listener->gain = 1.0;
-       G.listener->dopplerfactor = 1.0;
-       G.listener->dopplervelocity = 340.29f;
+       BKE_reports_init(CTX_wm_reports(C), RPT_STORE);
 }
+static void wm_free_reports(bContext *C)
+{
+       BKE_reports_clear(CTX_wm_reports(C));
+}
+
+
 
 /* only called once, for startup */
 void WM_init(bContext *C)
@@ -114,13 +115,14 @@ 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 */
        
        ED_file_init();                 /* for fsmenu */
        ED_init_node_butfuncs();        
        
-       BLF_init();
+       BLF_init(11, U.dpi);
        BLF_lang_init();
        
        init_builtin_keyingsets(); /* editors/animation/keyframing.c */
@@ -128,24 +130,20 @@ void WM_init(bContext *C)
        /* get the default database, plus a wm */
        WM_read_homefile(C, NULL);
        
-       UI_init();
+       wm_init_reports(C); /* reports cant be initialized before the wm */
        
-       /* goes away */
-       G.font= BMF_GetFont(BMF_kHelvetica12);
-       G.fonts= BMF_GetFont(BMF_kHelvetica10);
-       G.fontss= BMF_GetFont(BMF_kHelveticaBold8);
+       GPU_extensions_init();
+
+       UI_init();
        
        //      clear_matcopybuf(); /* XXX */
        
        //      glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
        
-       sound_init_listener();
 //     init_node_butfuncs();
        
        ED_preview_init_dbase();
        
-       GPU_extensions_init();
-       
        G.ndofdevice = -1;      /* XXX bad initializer, needs set otherwise buttons show! */
        
        read_Blog();
@@ -172,12 +170,16 @@ 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! */
 void WM_exit(bContext *C)
 {
        wmWindow *win;
-       
+
+       sound_exit();
+
        /* first wrap up running stuff, we assume only the active WM is running */
        /* modal handlers are on window level freed, others too? */
        /* note; same code copied in wm_files.c */
@@ -189,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)
@@ -202,10 +206,6 @@ void WM_exit(bContext *C)
 //     BIF_GlobalReebFree();
 //     BIF_freeRetarget();
        BIF_freeTemplates(C);
-       BIF_freeSketch(C);
-
-       /* Context should still working here. but radio tool needs cleaning... */
-       freeAllRad(CTX_data_scene(C));
        
        free_ttfont(); /* bke_font.h */
        
@@ -213,21 +213,17 @@ void WM_exit(bContext *C)
        
        BKE_freecubetable();
        
-//     if (G.background == 0)
-//             sound_end_all_sounds();
-       
-       
-       /* 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! */
+
+       if(C && CTX_wm_manager(C))
+               wm_free_reports(C);                     /* before free_blender! - since the ListBases get freed there */
+               
        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,13 +232,22 @@ void WM_exit(bContext *C)
        BLF_exit();
 
        RE_FreeAllRender();
+       RE_engines_exit();
        
 //     free_txt_data();
        
-//     sound_exit_audio();
-       if(G.listener) MEM_freeN(G.listener);
-       
-       
+
+#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
@@ -253,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);
@@ -264,17 +270,24 @@ void WM_exit(bContext *C)
        ED_file_exit(); /* for fsmenu */
 
        UI_exit();
-       BLI_freelistN(&U.themes);
+       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");
        
@@ -286,9 +299,6 @@ void WM_exit(bContext *C)
        }
 #endif 
        
-       
-       SYS_DeleteSystem(SYS_GetSystem());
-       
        exit(G.afbreek==1);
 }