svn merge -r36564:36583 https://svn.blender.org/svnroot/bf-blender/trunk/blender
[blender.git] / source / blender / windowmanager / intern / wm_init_exit.c
index 25ca8076b39656a43b051aa194bcaa2b96ed32fa..2a37654a23bc0a21d0491bdd9c7d692daa445f19 100644 (file)
@@ -1,4 +1,4 @@
-/**
+/*
  * $Id$
  *
  * ***** BEGIN GPL LICENSE BLOCK *****
  * $Id$
  *
  * ***** BEGIN GPL LICENSE BLOCK *****
  * ***** END GPL LICENSE BLOCK *****
  */
 
  * ***** END GPL LICENSE BLOCK *****
  */
 
+/** \file blender/windowmanager/intern/wm_init_exit.c
+ *  \ingroup wm
+ */
+
+
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
 #include "BKE_main.h"
 #include "BKE_mball.h"
 #include "BKE_report.h"
 #include "BKE_main.h"
 #include "BKE_mball.h"
 #include "BKE_report.h"
-#include "BKE_utildefines.h"
+
 #include "BKE_packedFile.h"
 #include "BKE_sequencer.h" /* free seq clipboard */
 #include "BKE_material.h" /* clear_matcopybuf */
 
 #include "BLI_blenlib.h"
 #include "BKE_packedFile.h"
 #include "BKE_sequencer.h" /* free seq clipboard */
 #include "BKE_material.h" /* clear_matcopybuf */
 
 #include "BLI_blenlib.h"
+#include "BLI_cellalloc.h"
+#include "BLI_winstuff.h"
 
 #include "RE_pipeline.h"               /* RE_ free stuff */
 
 
 #include "RE_pipeline.h"               /* RE_ free stuff */
 
 #endif
 
 #ifdef WITH_GAMEENGINE
 #endif
 
 #ifdef WITH_GAMEENGINE
-#include "SYS_System.h"
+#include "BL_System.h"
 #endif
 #endif
+#include "GHOST_Path-api.h"
+#include "GHOST_C-api.h"
 
 #include "RNA_define.h"
 
 
 #include "RNA_define.h"
 
 
 #include "BKE_depsgraph.h"
 #include "BKE_sound.h"
 
 #include "BKE_depsgraph.h"
 #include "BKE_sound.h"
-#include "GHOST_C-api.h"
 
 static void wm_init_reports(bContext *C)
 {
 
 static void wm_init_reports(bContext *C)
 {
@@ -108,16 +116,16 @@ static void wm_free_reports(bContext *C)
        BKE_reports_clear(CTX_wm_reports(C));
 }
 
        BKE_reports_clear(CTX_wm_reports(C));
 }
 
-
+int wm_start_with_console = 0;
 
 /* only called once, for startup */
 
 /* only called once, for startup */
-void WM_init(bContext *C, int argc, char **argv)
+void WM_init(bContext *C, int argc, const char **argv)
 {
 {
-
        if (!G.background) {
                wm_ghost_init(C);       /* note: it assigns C to ghost! */
                wm_init_cursor_data();
        }
        if (!G.background) {
                wm_ghost_init(C);       /* note: it assigns C to ghost! */
                wm_init_cursor_data();
        }
+       GHOST_CreateSystemPaths();
        wm_operatortype_init();
        
        set_free_windowmanager_cb(wm_close_and_free);   /* library.c */
        wm_operatortype_init();
        
        set_free_windowmanager_cb(wm_close_and_free);   /* library.c */
@@ -131,9 +139,8 @@ void WM_init(bContext *C, int argc, char **argv)
        
        BLF_init(11, U.dpi); /* Please update source/gamengine/GamePlayer/GPG_ghost.cpp if you change this */
        BLF_lang_init();
        
        BLF_init(11, U.dpi); /* Please update source/gamengine/GamePlayer/GPG_ghost.cpp if you change this */
        BLF_lang_init();
-       
        /* get the default database, plus a wm */
        /* get the default database, plus a wm */
-       WM_read_homefile(C, NULL);
+       WM_read_homefile(C, NULL, G.factory_startup);
 
        /* note: there is a bug where python needs initializing before loading the
         * startup.blend because it may contain PyDrivers. It also needs to be after
 
        /* note: there is a bug where python needs initializing before loading the
         * startup.blend because it may contain PyDrivers. It also needs to be after
@@ -144,16 +151,19 @@ void WM_init(bContext *C, int argc, char **argv)
         * Will try fix when the crash can be repeated. - campbell. */
 
 #ifdef WITH_PYTHON
         * Will try fix when the crash can be repeated. - campbell. */
 
 #ifdef WITH_PYTHON
-       BPY_set_context(C); /* necessary evil */
-       BPY_start_python(argc, argv);
+       BPY_context_set(C); /* necessary evil */
+       BPY_python_start(argc, argv);
 
 
-       BPY_reset_driver();
-       BPY_load_user_modules(C);
+       BPY_driver_reset();
+       BPY_modules_load_user(C);
 #else
        (void)argc; /* unused */
        (void)argv; /* unused */
 #endif
 
 #else
        (void)argc; /* unused */
        (void)argv; /* unused */
 #endif
 
+       if (!G.background && !wm_start_with_console)
+               GHOST_toggleConsole(3);
+
        wm_init_reports(C); /* reports cant be initialized before the wm */
 
        if (!G.background) {
        wm_init_reports(C); /* reports cant be initialized before the wm */
 
        if (!G.background) {
@@ -172,13 +182,15 @@ void WM_init(bContext *C, int argc, char **argv)
        
        G.ndofdevice = -1;      /* XXX bad initializer, needs set otherwise buttons show! */
        
        
        G.ndofdevice = -1;      /* XXX bad initializer, needs set otherwise buttons show! */
        
-       read_history();
+       WM_read_history();
 
 
+       /* allow a path of "", this is what happens when making a new file */
+       /*
        if(G.main->name[0] == 0)
                BLI_make_file_string("/", G.main->name, BLI_getDefaultDocumentFolder(), "untitled.blend");
        if(G.main->name[0] == 0)
                BLI_make_file_string("/", G.main->name, BLI_getDefaultDocumentFolder(), "untitled.blend");
+       */
 
        BLI_strncpy(G.lib, G.main->name, FILE_MAX);
 
        BLI_strncpy(G.lib, G.main->name, FILE_MAX);
-
 }
 
 void WM_init_splash(bContext *C)
 }
 
 void WM_init_splash(bContext *C)
@@ -268,13 +280,15 @@ int WM_init_game(bContext *C)
 
                /* full screen the area */
                if(!sa->full) {
 
                /* full screen the area */
                if(!sa->full) {
-                       ED_screen_full_toggle(C, wm->windows.first, sa);
+                       ED_screen_full_toggle(C, win, sa);
                }
 
                /* Fullscreen */
                if(scene->gm.fullscreen) {
                        WM_operator_name_call(C, "WM_OT_window_fullscreen_toggle", WM_OP_EXEC_DEFAULT, NULL);
                        wm_get_screensize(&ar->winrct.xmax, &ar->winrct.ymax);
                }
 
                /* Fullscreen */
                if(scene->gm.fullscreen) {
                        WM_operator_name_call(C, "WM_OT_window_fullscreen_toggle", WM_OP_EXEC_DEFAULT, NULL);
                        wm_get_screensize(&ar->winrct.xmax, &ar->winrct.ymax);
+                       ar->winx = ar->winrct.xmax + 1;
+                       ar->winy = ar->winrct.ymax + 1;
                }
                else
                {
                }
                else
                {
@@ -339,6 +353,7 @@ void WM_exit(bContext *C)
 
        sound_exit();
 
 
        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 */
        /* 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 */
@@ -410,14 +425,14 @@ void WM_exit(bContext *C)
        /* 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 */
        /* 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();
+       BPY_python_end();
 #endif
 
        if (!G.background) {
 // XXX         UI_filelist_free_icons();
        }
        
 #endif
 
        if (!G.background) {
 // XXX         UI_filelist_free_icons();
        }
        
-       GPU_buffer_pool_free(0);
+       GPU_buffer_pool_free(NULL);
        GPU_free_unused_buffers();
        GPU_extensions_exit();
        
        GPU_free_unused_buffers();
        GPU_extensions_exit();
        
@@ -433,7 +448,7 @@ void WM_exit(bContext *C)
        UI_exit();
        BKE_userdef_free();
 
        UI_exit();
        BKE_userdef_free();
 
-       RNA_exit(); /* should be after BPY_end_python so struct python slots are cleared */
+       RNA_exit(); /* should be after BPY_python_end so struct python slots are cleared */
        
        wm_ghost_exit();
 
        
        wm_ghost_exit();
 
@@ -441,9 +456,14 @@ void WM_exit(bContext *C)
 #ifdef WITH_GAMEENGINE
        SYS_DeleteSystem(SYS_GetSystem());
 #endif
 #ifdef WITH_GAMEENGINE
        SYS_DeleteSystem(SYS_GetSystem());
 #endif
+       
+       GHOST_DisposeSystemPaths();
+
        if(MEM_get_memory_blocks_in_use()!=0) {
        if(MEM_get_memory_blocks_in_use()!=0) {
-               printf("Error Totblock: %d\n", MEM_get_memory_blocks_in_use());
+               printf("Error: Not freed memory blocks: %d\n", MEM_get_memory_blocks_in_use()+BLI_cellalloc_get_totblock());
                MEM_printmemlist();
                MEM_printmemlist();
+               BLI_cellalloc_printleaks();
+               BLI_cellalloc_destroy();
        }
        wm_autosave_delete();
        
        }
        wm_autosave_delete();
        
@@ -456,7 +476,6 @@ void WM_exit(bContext *C)
                getchar();
        }
 #endif 
                getchar();
        }
 #endif 
-       
        exit(G.afbreek==1);
 }
 
        exit(G.afbreek==1);
 }