From 427040372443cd675c63495f0fab8c195b21319d Mon Sep 17 00:00:00 2001 From: qarmin Date: Fri, 3 May 2019 13:39:46 +0200 Subject: Fix crash when trying to set fallback or next pass with one of parent --- scene/resources/font.cpp | 8 +++++++- scene/resources/material.cpp | 7 ++++++- 2 files changed, 13 insertions(+), 2 deletions(-) (limited to 'scene') diff --git a/scene/resources/font.cpp b/scene/resources/font.cpp index c72ccc97db..5a1b560a98 100644 --- a/scene/resources/font.cpp +++ b/scene/resources/font.cpp @@ -497,7 +497,13 @@ Size2 Font::get_string_size(const String &p_string) const { } void BitmapFont::set_fallback(const Ref &p_fallback) { - ERR_FAIL_COND(p_fallback == this); + for (Ref fallback_child = p_fallback; fallback_child != NULL; fallback_child = fallback_child->get_fallback()) { + if (fallback_child == this) { + ERR_EXPLAIN("Can't set as fallback one of its parents to prevent crashes due to recursive loop."); + ERR_FAIL_COND(fallback_child == this); + } + } + fallback = p_fallback; } diff --git a/scene/resources/material.cpp b/scene/resources/material.cpp index 536eb11a27..5586116734 100644 --- a/scene/resources/material.cpp +++ b/scene/resources/material.cpp @@ -34,7 +34,12 @@ void Material::set_next_pass(const Ref &p_pass) { - ERR_FAIL_COND(p_pass == this); + for (Ref pass_child = p_pass; pass_child != NULL; pass_child = pass_child->get_next_pass()) { + if (pass_child == this) { + ERR_EXPLAIN("Can't set as next_pass one of its parents to prevent crashes due to recursive loop."); + ERR_FAIL_COND(pass_child == this); + } + } if (next_pass == p_pass) return; -- cgit v1.2.3