summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRémi Verschelde <rverschelde@gmail.com>2024-08-06 12:31:42 +0200
committerRémi Verschelde <rverschelde@gmail.com>2024-08-06 12:31:42 +0200
commit20eee3edd3e951d79fe5adbc2c336f6be5027c41 (patch)
tree44080823b3b9e4b39fa380bdba0a3322839b55e7
parentf544c461f0150ea92e8fe25bb63552407122d46f (diff)
parent5c8a8c57be58fdd3d71786ce5f45feb041713f67 (diff)
downloadredot-engine-20eee3edd3e951d79fe5adbc2c336f6be5027c41.tar.gz
Merge pull request #95083 from bruvzg/base_font_loops
[Font] Add check for cyclic base font dependencies.
-rw-r--r--scene/resources/font.cpp27
-rw-r--r--scene/resources/font.h5
2 files changed, 26 insertions, 6 deletions
diff --git a/scene/resources/font.cpp b/scene/resources/font.cpp
index 37d9d57722..104187775d 100644
--- a/scene/resources/font.cpp
+++ b/scene/resources/font.cpp
@@ -149,6 +149,25 @@ bool Font::_is_cyclic(const Ref<Font> &p_f, int p_depth) const {
return false;
}
+bool Font::_is_base_cyclic(const Ref<Font> &p_f, int p_depth) const {
+ ERR_FAIL_COND_V(p_depth > MAX_FALLBACK_DEPTH, true);
+ if (p_f.is_null()) {
+ return false;
+ }
+ if (p_f == this) {
+ return true;
+ }
+ Ref<FontVariation> fv = p_f;
+ if (fv.is_valid()) {
+ return _is_base_cyclic(fv->get_base_font(), p_depth + 1);
+ }
+ Ref<SystemFont> fs = p_f;
+ if (fs.is_valid()) {
+ return _is_base_cyclic(fs->get_base_font(), p_depth + 1);
+ }
+ return false;
+}
+
void Font::reset_state() {
_invalidate_rids();
}
@@ -2910,7 +2929,7 @@ Ref<Font> FontVariation::_get_base_font_or_default() const {
}
Ref<Font> f = theme->get_font(theme_name, E);
- if (f == this) {
+ if (_is_base_cyclic(f, 0)) {
continue;
}
if (f.is_valid()) {
@@ -2922,7 +2941,7 @@ Ref<Font> FontVariation::_get_base_font_or_default() const {
}
Ref<Font> f = global_context->get_fallback_theme()->get_font(theme_name, StringName());
- if (f != this) {
+ if (!_is_base_cyclic(f, 0)) {
if (f.is_valid()) {
theme_font = f;
theme_font->connect_changed(callable_mp(reinterpret_cast<Font *>(const_cast<FontVariation *>(this)), &Font::_invalidate_rids), CONNECT_REFERENCE_COUNTED);
@@ -3273,7 +3292,7 @@ Ref<Font> SystemFont::_get_base_font_or_default() const {
}
Ref<Font> f = theme->get_font(theme_name, E);
- if (f == this) {
+ if (_is_base_cyclic(f, 0)) {
continue;
}
if (f.is_valid()) {
@@ -3285,7 +3304,7 @@ Ref<Font> SystemFont::_get_base_font_or_default() const {
}
Ref<Font> f = global_context->get_fallback_theme()->get_font(theme_name, StringName());
- if (f != this) {
+ if (!_is_base_cyclic(f, 0)) {
if (f.is_valid()) {
theme_font = f;
theme_font->connect_changed(callable_mp(reinterpret_cast<Font *>(const_cast<SystemFont *>(this)), &Font::_invalidate_rids), CONNECT_REFERENCE_COUNTED);
diff --git a/scene/resources/font.h b/scene/resources/font.h
index 1878539a3f..68c391c35e 100644
--- a/scene/resources/font.h
+++ b/scene/resources/font.h
@@ -99,8 +99,6 @@ protected:
virtual void _update_rids_fb(const Ref<Font> &p_f, int p_depth) const;
virtual void _update_rids() const;
- virtual bool _is_cyclic(const Ref<Font> &p_f, int p_depth) const;
-
virtual void reset_state() override;
#ifndef DISABLE_DEPRECATED
@@ -110,6 +108,8 @@ protected:
#endif
public:
+ virtual bool _is_cyclic(const Ref<Font> &p_f, int p_depth) const;
+ virtual bool _is_base_cyclic(const Ref<Font> &p_f, int p_depth) const;
virtual void _invalidate_rids();
static constexpr int DEFAULT_FONT_SIZE = 16;
@@ -494,6 +494,7 @@ protected:
virtual void reset_state() override;
public:
+ virtual Ref<Font> get_base_font() const { return base_font; }
virtual Ref<Font> _get_base_font_or_default() const;
virtual void set_antialiasing(TextServer::FontAntialiasing p_antialiasing);