diff options
author | RĂ©mi Verschelde <remi@verschelde.fr> | 2021-05-14 10:30:31 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-05-14 10:30:31 +0200 |
commit | e6cd0056a8d484d76f3aeeeed9604a4eded66a2a (patch) | |
tree | d06434e2ceed5d7c8366b049740daf808ad73272 | |
parent | 420e75f2779b63bdb63d92b7b682944fa5ac8059 (diff) | |
parent | 2bae31a4df783de9fa3f6869f79bfe823c9d2664 (diff) |
Merge pull request #48584 from Zami77/remove-plugin-from-enabled-if-error
Remove plugin from enabled plugins, if there is an error
-rw-r--r-- | editor/editor_node.cpp | 26 | ||||
-rw-r--r-- | editor/editor_node.h | 1 |
2 files changed, 16 insertions, 11 deletions
diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp index 7aed5b2b7f..77c06dc5d5 100644 --- a/editor/editor_node.cpp +++ b/editor/editor_node.cpp @@ -738,6 +738,18 @@ void EditorNode::_on_plugin_ready(Object *p_script, const String &p_activate_nam push_item(script.operator->()); } +void EditorNode::_remove_plugin_from_enabled(const String &p_name) { + ProjectSettings *ps = ProjectSettings::get_singleton(); + PackedStringArray enabled_plugins = ps->get("editor_plugins/enabled"); + for (int i = 0; i < enabled_plugins.size(); ++i) { + if (enabled_plugins.get(i) == p_name) { + enabled_plugins.remove(i); + break; + } + } + ps->set("editor_plugins/enabled", enabled_plugins); +} + void EditorNode::_resources_changed(const Vector<String> &p_resources) { List<Ref<Resource>> changed; @@ -3120,16 +3132,7 @@ void EditorNode::set_addon_plugin_enabled(const String &p_addon, bool p_enabled, Ref<ConfigFile> cf; cf.instance(); if (!DirAccess::exists(p_addon.get_base_dir())) { - ProjectSettings *ps = ProjectSettings::get_singleton(); - PackedStringArray enabled_plugins = ps->get("editor_plugins/enabled"); - for (int i = 0; i < enabled_plugins.size(); ++i) { - if (enabled_plugins.get(i) == p_addon) { - enabled_plugins.remove(i); - break; - } - } - ps->set("editor_plugins/enabled", enabled_plugins); - ps->save(); + _remove_plugin_from_enabled(p_addon); WARN_PRINT("Addon '" + p_addon + "' failed to load. No directory found. Removing from enabled plugins."); return; } @@ -3159,7 +3162,8 @@ void EditorNode::set_addon_plugin_enabled(const String &p_addon, bool p_enabled, // Errors in the script cause the base_type to be an empty string. if (String(script->get_instance_base_type()) == "") { - show_warning(vformat(TTR("Unable to load addon script from path: '%s' There seems to be an error in the code, please check the syntax."), script_path)); + show_warning(vformat(TTR("Unable to load addon script from path: '%s'. This might be due to a code error in that script. \nDisabling the addon at '%s' to prevent further errors."), script_path, p_addon)); + _remove_plugin_from_enabled(p_addon); return; } diff --git a/editor/editor_node.h b/editor/editor_node.h index 07de183719..ec67a7c93a 100644 --- a/editor/editor_node.h +++ b/editor/editor_node.h @@ -460,6 +460,7 @@ private: void _update_file_menu_closed(); void _on_plugin_ready(Object *p_script, const String &p_activate_name); + void _remove_plugin_from_enabled(const String &p_name); void _fs_changed(); void _resources_reimported(const Vector<String> &p_resources); |