diff --git a/release/scripts/startup/bl_ui/space_toolsystem_common.py b/release/scripts/startup/bl_ui/space_toolsystem_common.py
index cde430c1e6f..2f25de24ca8 100644
--- a/release/scripts/startup/bl_ui/space_toolsystem_common.py
+++ b/release/scripts/startup/bl_ui/space_toolsystem_common.py
@@ -480,8 +480,7 @@ class ToolSelectPanelHelper:
kc_default.keymaps.new(km_idname, **km_kwargs)
@classmethod
- def register(cls):
- wm = bpy.context.window_manager
+ def _register_defer(cls, wm):
# Write into defaults, users may modify in preferences.
kc_default = wm.keyconfigs.default
@@ -510,6 +509,23 @@ class ToolSelectPanelHelper:
if callable(keymap_data[0]):
cls._km_action_simple(kc_default, kc_default, context_descr, item.label, keymap_data)
+ @classmethod
+ def register(cls):
+ try:
+ wm = bpy.context.window_manager
+ except:
+ # Delay registering tools until we have a window manager.
+ @bpy.app.handlers.persistent
+ def fn(_x, _y):
+ wm = bpy.context.window_manager
+ cls._register_defer(wm)
+ bpy.app.handlers.load_post.remove(fn)
+
+ bpy.app.handlers.load_post.append(fn)
+ return
+
+ cls._register_defer(wm)
+
@classmethod
def keymap_ui_hierarchy(cls, context_mode):
# See: bpy_extras.keyconfig_utils
diff --git a/source/blender/windowmanager/intern/wm_files.c b/source/blender/windowmanager/intern/wm_files.c
index abf957a6396..0a26395aced 100644
--- a/source/blender/windowmanager/intern/wm_files.c
+++ b/source/blender/windowmanager/intern/wm_files.c
@@ -673,6 +673,7 @@ static void wm_file_read_post(bContext *C,
if (use_data) {
/* important to do before NULL'ing the context */
BKE_callback_exec_null(bmain, BKE_CB_EVT_VERSION_UPDATE);
+ printf("Running post\n");
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);
diff --git a/source/blender/windowmanager/intern/wm_init_exit.c b/source/blender/windowmanager/intern/wm_init_exit.c
index d7ea47fc625..c3d26f5e06d 100644
--- a/source/blender/windowmanager/intern/wm_init_exit.c
+++ b/source/blender/windowmanager/intern/wm_init_exit.c
@@ -290,16 +290,6 @@ void WM_init(bContext *C, int argc, const char **argv)
BLI_assert((G.fileflags & G_FILE_NO_UI) == 0);
- wm_homefile_read(C,
- NULL,
- G.factory_startup,
- false,
- use_data,
- use_userdef,
- NULL,
- WM_init_state_app_template_get(),
- &is_factory_startup);
-
/* Call again to set from userpreferences... */
BLT_lang_set(NULL);
@@ -320,22 +310,12 @@ void WM_init(bContext *C, int argc, const char **argv)
if (!WM_platform_support_perform_checks()) {
exit(-1);
}
-
- UI_init();
}
BKE_subdiv_init();
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);
@@ -366,8 +346,6 @@ void WM_init(bContext *C, int argc, const char **argv)
}
#endif
- BLI_strncpy(G.lib, BKE_main_blendfile_path_from_global(), sizeof(G.lib));
-
#ifdef WITH_COMPOSITOR
if (1) {
extern void *COM_linker_hack;
@@ -375,29 +353,21 @@ 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_homefile_read(C,
+ NULL,
+ G.factory_startup,
+ false,
+ use_data,
+ use_userdef,
+ NULL,
+ WM_init_state_app_template_get(),
+ &is_factory_startup);
- wm_file_read_report(C, bmain);
+ BLI_strncpy(G.lib, BKE_main_blendfile_path_from_global(), sizeof(G.lib));
- if (!G.background) {
- CTX_wm_window_set(C, NULL);
- }
+ if (!G.background) {
+ /* Reads theme settings. */
+ UI_init();
}
}