浏览代码

Merge pull request #26978 from qarmin/fix_recursive_bitmapfont_crash

Fix crash when trying to set as Bitmap Font fallback one of his parent
Rémi Verschelde 6 年之前
父节点
当前提交
bf6f41e0b9
共有 2 个文件被更改,包括 13 次插入2 次删除
  1. 7 1
      scene/resources/font.cpp
  2. 6 1
      scene/resources/material.cpp

+ 7 - 1
scene/resources/font.cpp

@@ -530,7 +530,13 @@ Size2 Font::get_wordwrap_string_size(const String &p_string, float p_width) cons
 
 void BitmapFont::set_fallback(const Ref<BitmapFont> &p_fallback) {
 
-	ERR_FAIL_COND(p_fallback == this);
+	for (Ref<BitmapFont> 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;
 }
 

+ 6 - 1
scene/resources/material.cpp

@@ -38,7 +38,12 @@
 
 void Material::set_next_pass(const Ref<Material> &p_pass) {
 
-	ERR_FAIL_COND(p_pass == this);
+	for (Ref<Material> 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;