Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2020-09-14 10:50:01 +0300
committerJeroen Bakker <jeroen@blender.org>2020-09-21 10:30:36 +0300
commit27ea0862426d910badc6f81ce13d29a6ef3cc5f0 (patch)
tree6c3281e7fe01d0c19b5fea64e9db185aa3f5a5be
parent2c8f8765a1d815b15e0d9370a871b267d0ebe934 (diff)
Fix T80694: Crash reloading scripts from the Python console
Running `bpy.ops.script.reload()` from Python was crashing since the operator being called was it's self freed. Change the reload operator to defer execution - as supporting re-registration during execution is quite involved for a corner-case.
-rw-r--r--release/scripts/modules/bpy/utils/__init__.py2
-rw-r--r--source/blender/editors/space_script/script_edit.c35
-rw-r--r--source/blender/makesrna/intern/rna_wm_api.c12
3 files changed, 40 insertions, 9 deletions
diff --git a/release/scripts/modules/bpy/utils/__init__.py b/release/scripts/modules/bpy/utils/__init__.py
index 8a67a598ccd..4e0220ee1cc 100644
--- a/release/scripts/modules/bpy/utils/__init__.py
+++ b/release/scripts/modules/bpy/utils/__init__.py
@@ -283,6 +283,8 @@ def load_scripts(reload_scripts=False, refresh_scripts=False):
del _initialize
if reload_scripts:
+ _bpy.context.window_manager.tag_script_reload()
+
import gc
print("gc.collect() -> %d" % gc.collect())
diff --git a/source/blender/editors/space_script/script_edit.c b/source/blender/editors/space_script/script_edit.c
index e9ed1cec228..0c5cadf74e7 100644
--- a/source/blender/editors/space_script/script_edit.c
+++ b/source/blender/editors/space_script/script_edit.c
@@ -115,15 +115,32 @@ static int script_reload_exec(bContext *C, wmOperator *op)
return OPERATOR_CANCELLED;
}
- WM_script_tag_reload();
-
- /* TODO, this crashes on netrender and keying sets, need to look into why
- * disable for now unless running in debug mode */
- WM_cursor_wait(1);
- BPY_execute_string(
- C, (const char *[]){"bpy", NULL}, "bpy.utils.load_scripts(reload_scripts=True)");
- WM_cursor_wait(0);
- WM_event_add_notifier(C, NC_WINDOW, NULL);
+ /* TODO(campbell): this crashes on netrender and keying sets, need to look into why
+ * disable for now unless running in debug mode. */
+
+ /* It would be nice if we could detect when this is called from the Python
+ * only postponing in that case, for now always do it. */
+ if (true) {
+ /* Postpone when called from Python so this can be called from an operator
+ * that might be re-registered, crashing Blender when we try to read from the
+ * freed operator type which, see T80694. */
+ BPY_execute_string(C,
+ (const char *[]){"bpy", NULL},
+ "def fn():\n"
+ " bpy.utils.load_scripts(reload_scripts=True)\n"
+ " return None\n"
+ "bpy.app.timers.register(fn)");
+ }
+ else {
+ WM_cursor_wait(true);
+ BPY_execute_string(
+ C, (const char *[]){"bpy", NULL}, "bpy.utils.load_scripts(reload_scripts=True)");
+ WM_cursor_wait(false);
+ }
+
+ /* Note that #WM_script_tag_reload is called from `bpy.utils.load_scripts`,
+ * any additional updates required by this operator should go there. */
+
return OPERATOR_FINISHED;
#else
UNUSED_VARS(C, op);
diff --git a/source/blender/makesrna/intern/rna_wm_api.c b/source/blender/makesrna/intern/rna_wm_api.c
index ee7ff472c12..8d7a3cddbc5 100644
--- a/source/blender/makesrna/intern/rna_wm_api.c
+++ b/source/blender/makesrna/intern/rna_wm_api.c
@@ -558,6 +558,12 @@ static void rna_WindowManager_print_undo_steps(wmWindowManager *wm)
BKE_undosys_print(wm->undo_stack);
}
+static void rna_WindowManager_tag_script_reload(void)
+{
+ WM_script_tag_reload();
+ WM_main_add_notifier(NC_WINDOW, NULL);
+}
+
static PointerRNA rna_WindoManager_operator_properties_last(const char *idname)
{
wmOperatorType *ot = WM_operatortype_find(idname, true);
@@ -913,6 +919,12 @@ void RNA_api_wm(StructRNA *srna)
RNA_def_function(srna, "print_undo_steps", "rna_WindowManager_print_undo_steps");
+ /* Used by (#SCRIPT_OT_reload). */
+ func = RNA_def_function(srna, "tag_script_reload", "rna_WindowManager_tag_script_reload");
+ RNA_def_function_ui_description(
+ func, "Tag for refreshing the interface after scripts have been reloaded");
+ RNA_def_function_flag(func, FUNC_NO_SELF);
+
parm = RNA_def_property(srna, "is_interface_locked", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_ui_text(
parm,