From bb5fa91a6be1cec688267b3ff43bb7a4d8cbf951 Mon Sep 17 00:00:00 2001 From: Yuri Sizov Date: Wed, 24 Aug 2022 18:45:14 +0300 Subject: [PATCH] Disconnect Control from theme resources to avoid issues on destruction --- scene/gui/control.cpp | 21 +++++++++++++++++++++ scene/gui/control.h | 1 + 2 files changed, 22 insertions(+) diff --git a/scene/gui/control.cpp b/scene/gui/control.cpp index 66cb41ee656..03fcef17f58 100644 --- a/scene/gui/control.cpp +++ b/scene/gui/control.cpp @@ -3622,3 +3622,24 @@ void Control::_bind_methods() { GDVIRTUAL_BIND(_gui_input, "event"); } + +Control::~Control() { + // Resources need to be disconnected. + for (KeyValue> &E : data.icon_override) { + E.value->disconnect("changed", callable_mp(this, &Control::_theme_property_override_changed)); + } + for (KeyValue> &E : data.style_override) { + E.value->disconnect("changed", callable_mp(this, &Control::_theme_property_override_changed)); + } + for (KeyValue> &E : data.font_override) { + E.value->disconnect("changed", callable_mp(this, &Control::_theme_property_override_changed)); + } + + // Then override maps can be simply cleared. + data.icon_override.clear(); + data.style_override.clear(); + data.font_override.clear(); + data.font_size_override.clear(); + data.color_override.clear(); + data.constant_override.clear(); +} diff --git a/scene/gui/control.h b/scene/gui/control.h index d7e120260c1..c69067f82f6 100644 --- a/scene/gui/control.h +++ b/scene/gui/control.h @@ -610,6 +610,7 @@ public: virtual Control *make_custom_tooltip(const String &p_text) const; Control() {} + ~Control(); }; VARIANT_ENUM_CAST(Control::FocusMode);