From b8bf2ec3cdedee92cb80a1418883d58459fd4f3e Mon Sep 17 00:00:00 2001 From: anazr9 Date: Sun, 22 Aug 2021 14:17:01 +0530 Subject: [PATCH 1/3] fixed crash with RichTextLabel [fill] tag #51968 by using 3.3 as reference --- scene/gui/rich_text_label.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/scene/gui/rich_text_label.cpp b/scene/gui/rich_text_label.cpp index 9ac3ef0380..4db1b5ba6c 100644 --- a/scene/gui/rich_text_label.cpp +++ b/scene/gui/rich_text_label.cpp @@ -180,6 +180,7 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int & } int wofs = margin; + int spaces_size = 0; int align_ofs = 0; if (p_mode != PROCESS_CACHE && align != ALIGN_FILL) { @@ -247,6 +248,7 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int & line_ascent = 0; \ line_descent = 0; \ spaces = 0; \ + spaces_size = 0; \ wofs = begin; \ align_ofs = 0; \ if (p_mode != PROCESS_CACHE) { \ @@ -447,7 +449,9 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int & fh = line_ascent + line_descent; if (end && c[end - 1] == ' ') { - if (align == ALIGN_FILL) { + if (p_mode == PROCESS_CACHE) { + spaces_size += font->get_char_size(' ').width; + } else if (align == ALIGN_FILL) { int ln = MIN(l.offset_caches.size() - 1, line); if (l.space_caches[ln]) { align_ofs = spaces * l.offset_caches[ln] / l.space_caches[ln]; From 9b06355488a79fcdd642a81546400bdab9af2027 Mon Sep 17 00:00:00 2001 From: Anas Saifi <74458687+anazr9@users.noreply.github.com> Date: Sun, 22 Aug 2021 15:18:52 +0530 Subject: [PATCH 2/3] Update scene/gui/rich_text_label.cpp Co-authored-by: bruvzg <7645683+bruvzg@users.noreply.github.com> --- scene/gui/rich_text_label.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/scene/gui/rich_text_label.cpp b/scene/gui/rich_text_label.cpp index 4db1b5ba6c..96fc02624a 100644 --- a/scene/gui/rich_text_label.cpp +++ b/scene/gui/rich_text_label.cpp @@ -449,9 +449,7 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int & fh = line_ascent + line_descent; if (end && c[end - 1] == ' ') { - if (p_mode == PROCESS_CACHE) { - spaces_size += font->get_char_size(' ').width; - } else if (align == ALIGN_FILL) { + if (align == ALIGN_FILL && p_mode != PROCESS_CACHE) { int ln = MIN(l.offset_caches.size() - 1, line); if (l.space_caches[ln]) { align_ofs = spaces * l.offset_caches[ln] / l.space_caches[ln]; From 48742705920296dee32ecf8d8be3f73f343adc30 Mon Sep 17 00:00:00 2001 From: Anas Saifi <74458687+anazr9@users.noreply.github.com> Date: Sun, 22 Aug 2021 15:58:45 +0530 Subject: [PATCH 3/3] Removed unused variable --- scene/gui/rich_text_label.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/scene/gui/rich_text_label.cpp b/scene/gui/rich_text_label.cpp index 96fc02624a..ca3b2b9e87 100644 --- a/scene/gui/rich_text_label.cpp +++ b/scene/gui/rich_text_label.cpp @@ -180,7 +180,6 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int & } int wofs = margin; - int spaces_size = 0; int align_ofs = 0; if (p_mode != PROCESS_CACHE && align != ALIGN_FILL) { @@ -248,7 +247,6 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int & line_ascent = 0; \ line_descent = 0; \ spaces = 0; \ - spaces_size = 0; \ wofs = begin; \ align_ofs = 0; \ if (p_mode != PROCESS_CACHE) { \