From a354125d7d9f07860d2d9a629eee2e108fbfe25e Mon Sep 17 00:00:00 2001 From: bruvzg <7645683+bruvzg@users.noreply.github.com> Date: Mon, 15 Feb 2021 22:57:42 +0200 Subject: [PATCH] Fix `TextLine`/`TextParagraph` crash when `add_string` / `set_dropcap` is called null font reference. --- scene/resources/text_line.cpp | 1 + scene/resources/text_paragraph.cpp | 2 ++ 2 files changed, 3 insertions(+) diff --git a/scene/resources/text_line.cpp b/scene/resources/text_line.cpp index ed69c093cf4..925867a1f20 100644 --- a/scene/resources/text_line.cpp +++ b/scene/resources/text_line.cpp @@ -167,6 +167,7 @@ void TextLine::set_bidi_override(const Vector &p_override) { } bool TextLine::add_string(const String &p_text, const Ref &p_fonts, int p_size, const Dictionary &p_opentype_features, const String &p_language) { + ERR_FAIL_COND_V(p_fonts.is_null(), false); bool res = TS->shaped_text_add_string(rid, p_text, p_fonts->get_rids(), p_size, p_opentype_features, p_language); spacing_top = p_fonts->get_spacing(Font::SPACING_TOP); spacing_bottom = p_fonts->get_spacing(Font::SPACING_BOTTOM); diff --git a/scene/resources/text_paragraph.cpp b/scene/resources/text_paragraph.cpp index 94957df510a..444a4bb22a1 100644 --- a/scene/resources/text_paragraph.cpp +++ b/scene/resources/text_paragraph.cpp @@ -243,6 +243,7 @@ TextServer::Orientation TextParagraph::get_orientation() const { } bool TextParagraph::set_dropcap(const String &p_text, const Ref &p_fonts, int p_size, const Rect2 &p_dropcap_margins, const Dictionary &p_opentype_features, const String &p_language) { + ERR_FAIL_COND_V(p_fonts.is_null(), false); TS->shaped_text_clear(dropcap_rid); dropcap_margins = p_dropcap_margins; bool res = TS->shaped_text_add_string(dropcap_rid, p_text, p_fonts->get_rids(), p_size, p_opentype_features, p_language); @@ -257,6 +258,7 @@ void TextParagraph::clear_dropcap() { } bool TextParagraph::add_string(const String &p_text, const Ref &p_fonts, int p_size, const Dictionary &p_opentype_features, const String &p_language) { + ERR_FAIL_COND_V(p_fonts.is_null(), false); bool res = TS->shaped_text_add_string(rid, p_text, p_fonts->get_rids(), p_size, p_opentype_features, p_language); spacing_top = p_fonts->get_spacing(Font::SPACING_TOP); spacing_bottom = p_fonts->get_spacing(Font::SPACING_BOTTOM);