Skip to content

armgit / godot

Public Imported from GitHub
0

Godot Engine – Multi-platform 2D and 3D game engine

Fix `EditorPlugin::remove_control_from_docks` freeing passed control

kleonccdc278dfa6cc
diff --git a/editor/plugins/editor_plugin.cpp b/editor/plugins/editor_plugin.cpp
index be0bb7e8b1b..95fba96b035 100644
--- a/editor/plugins/editor_plugin.cpp
+++ b/editor/plugins/editor_plugin.cpp
@@ -93,6 +93,7 @@ Button *EditorPlugin::add_control_to_bottom_panel(Control *p_control, const Stri
void EditorPlugin::add_control_to_dock(DockSlot p_slot, Control *p_control, const Ref<Shortcut> &p_shortcut) {
ERR_FAIL_NULL(p_control);
ERR_FAIL_COND(legacy_docks.has(p_control));
+ ERR_FAIL_COND(p_control->get_parent() != nullptr);
EditorDock *dock = memnew(EditorDock);
dock->set_title(p_control->get_name());
@@ -108,6 +109,9 @@ void EditorPlugin::remove_control_from_docks(Control *p_control) {
ERR_FAIL_NULL(p_control);
ERR_FAIL_COND(!legacy_docks.has(p_control));
+ // Ensure freeing the legacy dock won't free `p_control` (freeing it is up to the user).
+ legacy_docks[p_control]->remove_child(p_control);
+
EditorDockManager::get_singleton()->remove_dock(legacy_docks[p_control]);
legacy_docks[p_control]->queue_free();
legacy_docks.erase(p_control);