diff --git a/source/blender/windowmanager/intern/wm_files.c b/source/blender/windowmanager/intern/wm_files.c index abf957a6396..581676bb1e9 100644 --- a/source/blender/windowmanager/intern/wm_files.c +++ b/source/blender/windowmanager/intern/wm_files.c @@ -1294,7 +1294,7 @@ void wm_homefile_read(bContext *C, wm_window_match_do(C, &wmbase, &bmain->wm, &bmain->wm); } - if (use_userdef) { + if (use_userdef && (bmain != NULL)) { /* Clear keymaps because the current default keymap may have been initialized * from user preferences, which have been reset. */ LISTBASE_FOREACH (wmWindowManager *, wm, &bmain->wm) { diff --git a/source/blender/windowmanager/intern/wm_init_exit.c b/source/blender/windowmanager/intern/wm_init_exit.c index d7ea47fc625..dcbe8ee0a9e 100644 --- a/source/blender/windowmanager/intern/wm_init_exit.c +++ b/source/blender/windowmanager/intern/wm_init_exit.c @@ -290,11 +290,20 @@ void WM_init(bContext *C, int argc, const char **argv) BLI_assert((G.fileflags & G_FILE_NO_UI) == 0); +#ifdef WITH_PYTHON + BPY_python_start(C, argc, argv); + BPY_python_reset(C); +#else + (void)argc; /* unused */ + (void)argv; /* unused */ +#endif + + /* Load preferences only. */ wm_homefile_read(C, NULL, G.factory_startup, false, - use_data, + false, /* Don't load data. */ use_userdef, NULL, WM_init_state_app_template_get(), @@ -328,22 +337,6 @@ void WM_init(bContext *C, int argc, const char **argv) ED_spacemacros_init(); - /* NOTE(campbell): there is a bug where python needs initializing before loading the - * startup.blend because it may contain PyDrivers. It also needs to be after - * initializing space types and other internal data. - * - * However can't redo this at the moment. Solution is to load python - * before wm_homefile_read() or make py-drivers check if python is running. - * Will try fix when the crash can be repeated. */ - -#ifdef WITH_PYTHON - BPY_python_start(C, argc, argv); - BPY_python_reset(C); -#else - (void)argc; /* unused */ - (void)argv; /* unused */ -#endif - if (!G.background) { if (wm_start_with_console) { GHOST_toggleConsole(1); @@ -375,30 +368,16 @@ void WM_init(bContext *C, int argc, const char **argv) } #endif - { - Main *bmain = CTX_data_main(C); - /* NOTE: logic here is from wm_file_read_post, - * call functions that depend on Python being initialized. */ - - /* normally 'wm_homefile_read' will do this, - * however python is not initialized when called from this function. - * - * unlikely any handlers are set but its possible, - * note that recovering the last session does its own callbacks. */ - CTX_wm_window_set(C, CTX_wm_manager(C)->windows.first); - - BKE_callback_exec_null(bmain, BKE_CB_EVT_VERSION_UPDATE); - BKE_callback_exec_null(bmain, BKE_CB_EVT_LOAD_POST); - if (is_factory_startup) { - BKE_callback_exec_null(bmain, BKE_CB_EVT_LOAD_FACTORY_STARTUP_POST); - } - - wm_file_read_report(C, bmain); - - if (!G.background) { - CTX_wm_window_set(C, NULL); - } - } + /* Load data only. */ + wm_homefile_read(C, + NULL, + G.factory_startup, + false, + use_data, + false, /* No preferences. */ + NULL, + WM_init_state_app_template_get(), + &is_factory_startup); } void WM_init_splash(bContext *C)