[Bf-blender-cvs] [f0df4d6c35f] master: Fix T67577: Add-on unregister can't access preferences on factory reset

Campbell Barton noreply at git.blender.org
Wed Jun 3 06:48:23 CEST 2020


Commit: f0df4d6c35fc17c57adc8c0bcd5af11f7583f2ee
Author: Campbell Barton
Date:   Wed Jun 3 14:34:18 2020 +1000
Branches: master
https://developer.blender.org/rBf0df4d6c35fc17c57adc8c0bcd5af11f7583f2ee

Fix T67577: Add-on unregister can't access preferences on factory reset

===================================================================

M	release/scripts/modules/bl_app_template_utils.py
M	source/blender/windowmanager/intern/wm_files.c

===================================================================

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) {



More information about the Bf-blender-cvs mailing list