From c6725b935c2d84c6649682aba4499417dbd8f358 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Tue, 25 Jul 2023 15:32:31 +1000 Subject: [PATCH] Fix #109720: load_post can't be used to initialize the driver namespace Regression in [0] changed the order of execution for the load_post handler which previously (in 3.5x) ran before driver evaluation. Calling either load_post/load_post_fail handlers after loading was changed intentionally to simplify the code-path for calling handlers however it meant the handler couldn't be used to setup drivers, so restore the original logic. [0]: 46be42f6b16314f59a37ebb430d77d12e7a88461 --- .../blender/windowmanager/intern/wm_files.cc | 25 ++++++++++++++----- 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/source/blender/windowmanager/intern/wm_files.cc b/source/blender/windowmanager/intern/wm_files.cc index 95621329cd6..6e67487bbb1 100644 --- a/source/blender/windowmanager/intern/wm_files.cc +++ b/source/blender/windowmanager/intern/wm_files.cc @@ -668,7 +668,9 @@ struct wmFileReadPost_Params { * Logic shared between #WM_file_read & #wm_homefile_read, * updates to make after reading a file. */ -static void wm_file_read_post(bContext *C, const wmFileReadPost_Params *params) +static void wm_file_read_post(bContext *C, + const char *filepath, + const wmFileReadPost_Params *params) { wmWindowManager *wm = CTX_wm_manager(C); @@ -753,6 +755,13 @@ static void wm_file_read_post(bContext *C, const wmFileReadPost_Params *params) if (use_data) { /* Important to do before nulling the context. */ BKE_callback_exec_null(bmain, BKE_CB_EVT_VERSION_UPDATE); + + /* Load-post must run before evaluating drivers & depsgraph, see: #109720. + * On failure, the caller handles #BKE_CB_EVT_LOAD_POST_FAIL. */ + if (params->success) { + BKE_callback_exec_string(bmain, BKE_CB_EVT_LOAD_POST, filepath); + } + if (is_factory_startup) { BKE_callback_exec_null(bmain, BKE_CB_EVT_LOAD_FACTORY_STARTUP_POST); } @@ -827,8 +836,11 @@ static void wm_read_callback_post_wrapper(bContext *C, const char *filepath, con wmWindow *win = static_cast(wm->windows.first); CTX_wm_window_set(C, win); } - BKE_callback_exec_string( - bmain, success ? BKE_CB_EVT_LOAD_POST : BKE_CB_EVT_LOAD_POST_FAIL, filepath); + + /* On success: #BKE_CB_EVT_LOAD_POST runs from #wm_file_read_post. */ + if (success == false) { + BKE_callback_exec_string(bmain, BKE_CB_EVT_LOAD_POST_FAIL, filepath); + } /* This function should leave the window null when the function entered. */ if (!has_window) { @@ -1048,7 +1060,7 @@ bool WM_file_read(bContext *C, const char *filepath, ReportList *reports) read_file_post_params.reset_app_template = false; read_file_post_params.success = true; read_file_post_params.is_alloc = false; - wm_file_read_post(C, &read_file_post_params); + wm_file_read_post(C, filepath, &read_file_post_params); bf_reports.duration.whole = PIL_check_seconds_timer() - bf_reports.duration.whole; file_read_reports_finalize(&bf_reports); @@ -1485,10 +1497,11 @@ void wm_homefile_read(bContext *C, void wm_homefile_read_post(bContext *C, const wmFileReadPost_Params *params_file_read_post) { - wm_file_read_post(C, params_file_read_post); + const char *filepath = ""; + wm_file_read_post(C, filepath, params_file_read_post); if (params_file_read_post->use_data) { - wm_read_callback_post_wrapper(C, "", params_file_read_post->success); + wm_read_callback_post_wrapper(C, filepath, params_file_read_post->success); } if (params_file_read_post->is_alloc) {