From f0df4d6c35fc17c57adc8c0bcd5af11f7583f2ee Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Wed, 3 Jun 2020 14:34:18 +1000 Subject: [PATCH] Fix T67577: Add-on unregister can't access preferences on factory reset --- release/scripts/modules/bl_app_template_utils.py | 4 ---- source/blender/windowmanager/intern/wm_files.c | 15 +++++++++++++++ 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/release/scripts/modules/bl_app_template_utils.py b/release/scripts/modules/bl_app_template_utils.py index 42467d21580..6ee1e2ab8df 100644 --- a/release/scripts/modules/bl_app_template_utils.py +++ b/release/scripts/modules/bl_app_template_utils.py @@ -170,10 +170,6 @@ def activate(template_id=None): if template_id_prev: _disable(template_id_prev) - # Disable all addons, afterwards caller must reset. - import addon_utils - addon_utils.disable_all() - # ignore_not_found so modules that don't contain scripts don't raise errors _mod = _enable(template_id, ignore_not_found=True) if template_id else None diff --git a/source/blender/windowmanager/intern/wm_files.c b/source/blender/windowmanager/intern/wm_files.c index 41cc00a3e3f..d278cafb821 100644 --- a/source/blender/windowmanager/intern/wm_files.c +++ b/source/blender/windowmanager/intern/wm_files.c @@ -846,6 +846,21 @@ void wm_homefile_read(bContext *C, SET_FLAG_FROM_TEST(G.f, (U.flag & USER_SCRIPT_AUTOEXEC_DISABLE) == 0, G_FLAG_SCRIPT_AUTOEXEC); } + if (use_userdef || reset_app_template) { +#ifdef WITH_PYTHON + /* This only runs once Blender has already started. */ + if (CTX_py_init_get(C)) { + /* This is restored by 'wm_file_read_post', disable before loading any preferences + * so an add-on can read their own preferences when un-registering, + * and use new preferences if/when re-registering, see T67577. + * + * Note that this fits into 'wm_file_read_pre' function but gets messy + * since we need to know if 'reset_app_template' is true. */ + BPY_execute_string(C, (const char *[]){"addon_utils", NULL}, "addon_utils.disable_all()"); + } +#endif /* WITH_PYTHON */ + } + wm_file_read_pre(C, use_data, use_userdef); if (use_data) {