From f9fbe92e8a2f9f1e1e83edbb4898149453c757f1 Mon Sep 17 00:00:00 2001 From: bruvzg <7645683+bruvzg@users.noreply.github.com> Date: Mon, 23 May 2022 18:06:32 +0300 Subject: [PATCH] [Label3D, 4.x] Monitor default theme font changes, to prevent use of invalid materials. --- scene/3d/label_3d.cpp | 26 +++++++++++++++++++++++--- scene/3d/label_3d.h | 1 + 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/scene/3d/label_3d.cpp b/scene/3d/label_3d.cpp index 2d7da48ab1d..78da22a0c30 100644 --- a/scene/3d/label_3d.cpp +++ b/scene/3d/label_3d.cpp @@ -788,6 +788,11 @@ Ref Label3D::get_font() const { } Ref Label3D::_get_font_or_default() const { + if (theme_font.is_valid()) { + theme_font->disconnect(CoreStringNames::get_singleton()->changed, Callable(const_cast(this), "_font_changed")); + theme_font.unref(); + } + if (font_override.is_valid() && font_override->get_data_count() > 0) { return font_override; } @@ -799,7 +804,12 @@ Ref Label3D::_get_font_or_default() const { for (const StringName &E : theme_types) { if (Theme::get_project_default()->has_theme_item(Theme::DATA_TYPE_FONT, "font", E)) { - return Theme::get_project_default()->get_theme_item(Theme::DATA_TYPE_FONT, "font", E); + Ref f = Theme::get_project_default()->get_theme_item(Theme::DATA_TYPE_FONT, "font", E); + if (f.is_valid()) { + theme_font = f; + theme_font->connect(CoreStringNames::get_singleton()->changed, Callable(const_cast(this), "_font_changed")); + } + return f; } } } @@ -811,13 +821,23 @@ Ref Label3D::_get_font_or_default() const { for (const StringName &E : theme_types) { if (Theme::get_default()->has_theme_item(Theme::DATA_TYPE_FONT, "font", E)) { - return Theme::get_default()->get_theme_item(Theme::DATA_TYPE_FONT, "font", E); + Ref f = Theme::get_default()->get_theme_item(Theme::DATA_TYPE_FONT, "font", E); + if (f.is_valid()) { + theme_font = f; + theme_font->connect(CoreStringNames::get_singleton()->changed, Callable(const_cast(this), "_font_changed")); + } + return f; } } } // If they don't exist, use any type to return the default/empty value. - return Theme::get_default()->get_theme_item(Theme::DATA_TYPE_FONT, "font", StringName()); + Ref f = Theme::get_default()->get_theme_item(Theme::DATA_TYPE_FONT, "font", StringName()); + if (f.is_valid()) { + theme_font = f; + theme_font->connect(CoreStringNames::get_singleton()->changed, Callable(const_cast(this), "_font_changed")); + } + return f; } void Label3D::set_font_size(int p_size) { diff --git a/scene/3d/label_3d.h b/scene/3d/label_3d.h index f57797a247d..62f4c3fe966 100644 --- a/scene/3d/label_3d.h +++ b/scene/3d/label_3d.h @@ -96,6 +96,7 @@ private: int font_size = 16; Ref font_override; + mutable Ref theme_font; Color modulate = Color(1, 1, 1, 1); Point2 lbl_offset; int outline_render_priority = -1;