Browse Source

Merge pull request #66551 from bruvzg/font_is_cyclic

Fix Font::_is_cyclic.
Rémi Verschelde 2 năm trước cách đây
mục cha
commit
67f79819e7
1 tập tin đã thay đổi với 9 bổ sung4 xóa
  1. 9 4
      scene/resources/font.cpp

+ 9 - 4
scene/resources/font.cpp

@@ -127,16 +127,18 @@ void Font::_invalidate_rids() {
 }
 
 bool Font::_is_cyclic(const Ref<Font> &p_f, int p_depth) const {
-	ERR_FAIL_COND_V(p_depth > MAX_FALLBACK_DEPTH, false);
+	ERR_FAIL_COND_V(p_depth > MAX_FALLBACK_DEPTH, true);
 	if (p_f.is_null()) {
 		return false;
 	}
+	if (p_f == this) {
+		return true;
+	}
 	for (int i = 0; i < p_f->fallbacks.size(); i++) {
 		const Ref<Font> &f = p_f->fallbacks[i];
-		if (f == this) {
+		if (_is_cyclic(f, p_depth + 1)) {
 			return true;
 		}
-		return _is_cyclic(f, p_depth + 1);
 	}
 	return false;
 }
@@ -147,7 +149,10 @@ void Font::reset_state() {
 
 // Fallbacks.
 void Font::set_fallbacks(const TypedArray<Font> &p_fallbacks) {
-	ERR_FAIL_COND(_is_cyclic(this, 0));
+	for (int i = 0; i < p_fallbacks.size(); i++) {
+		const Ref<Font> &f = p_fallbacks[i];
+		ERR_FAIL_COND_MSG(_is_cyclic(f, 0), "Cyclic font fallback.");
+	}
 	for (int i = 0; i < fallbacks.size(); i++) {
 		Ref<Font> f = fallbacks[i];
 		if (f.is_valid()) {