diff options
-rw-r--r-- | release/scripts/modules/bpy/utils/__init__.py | 2 | ||||
-rw-r--r-- | source/blender/editors/space_script/script_edit.c | 35 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_wm_api.c | 12 |
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 f739bfe367e..56f99d31cf1 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_run_string_eval( - 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_run_string_exec(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_run_string_eval( + 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, |