From c151c7dce0b3802ddf2caa2bb2d6a227d7326c3f Mon Sep 17 00:00:00 2001 From: bruvzg <7645683+bruvzg@users.noreply.github.com> Date: Tue, 9 Jul 2024 09:48:45 +0300 Subject: [PATCH] [Editor] Unload addons when using `--import` or `--quit`. --- editor/editor_node.cpp | 8 ++++++-- editor/editor_node.h | 1 + main/main.cpp | 12 ++++++++++++ 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp index fd49920c6b1..870c74b3482 100644 --- a/editor/editor_node.cpp +++ b/editor/editor_node.cpp @@ -3340,13 +3340,17 @@ void EditorNode::_exit_editor(int p_exit_code) { dim_editor(true); // Unload addons before quitting to allow cleanup. + unload_editor_addons(); + + get_tree()->quit(p_exit_code); +} + +void EditorNode::unload_editor_addons() { for (const KeyValue &E : addon_name_to_plugin) { print_verbose(vformat("Unloading addon: %s", E.key)); remove_editor_plugin(E.value, false); memdelete(E.value); } - - get_tree()->quit(p_exit_code); } void EditorNode::_discard_changes(const String &p_str) { diff --git a/editor/editor_node.h b/editor/editor_node.h index 7a26156ab8d..a2ee61697f3 100644 --- a/editor/editor_node.h +++ b/editor/editor_node.h @@ -908,6 +908,7 @@ public: void save_before_run(); void try_autosave(); void restart_editor(); + void unload_editor_addons(); void dim_editor(bool p_dimming); bool is_editor_dimmed() const; diff --git a/main/main.cpp b/main/main.cpp index 060b3fe2f60..c43fc7078b9 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -4176,7 +4176,13 @@ bool Main::iteration() { movie_writer->add_frame(); } +#ifdef TOOLS_ENABLED + bool quit_after_timeout = false; +#endif if ((quit_after > 0) && (Engine::get_singleton()->_process_frames >= quit_after)) { +#ifdef TOOLS_ENABLED + quit_after_timeout = true; +#endif exit = true; } @@ -4209,6 +4215,12 @@ bool Main::iteration() { } #endif +#ifdef TOOLS_ENABLED + if (exit && quit_after_timeout && EditorNode::get_singleton()) { + EditorNode::get_singleton()->unload_editor_addons(); + } +#endif + return exit; }