Fix Font::_is_cyclic.

This commit is contained in:
bruvzg 2022-09-28 17:47:34 +03:00
parent 14e1f36e61
commit 155694c7c6
No known key found for this signature in database
GPG key ID: 7960FCF39844EC38

View file

@ -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()) {