summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRémi Verschelde <rverschelde@gmail.com>2023-01-17 15:00:11 +0100
committerRémi Verschelde <rverschelde@gmail.com>2023-01-17 15:00:11 +0100
commit9ebb3e3107bee82da2b4eafad685978c26bc1a2c (patch)
treecf7457d979a923e65e2fea9b36f2cb5b089ac245
parentee7beff3c4b21191897dd32c2e942c023083174b (diff)
parented8c5cd52f7914daf6f1aa309581ca3b9b048a2e (diff)
downloadredot-engine-9ebb3e3107bee82da2b4eafad685978c26bc1a2c.tar.gz
Merge pull request #71553 from RandomShaper/no_catastrophic_relayout
Prevent infinite cascade of re-layout after label text reshaping
-rw-r--r--scene/gui/label.cpp9
-rw-r--r--scene/gui/label.h2
2 files changed, 10 insertions, 1 deletions
diff --git a/scene/gui/label.cpp b/scene/gui/label.cpp
index cafea83f16..f59702835c 100644
--- a/scene/gui/label.cpp
+++ b/scene/gui/label.cpp
@@ -222,6 +222,7 @@ void Label::_shape() {
}
}
lines_dirty = false;
+ lines_shaped_last_width = get_size().width;
}
_update_visible();
@@ -596,7 +597,13 @@ void Label::_notification(int p_what) {
} break;
case NOTIFICATION_RESIZED: {
- lines_dirty = true;
+ // It may happen that the reshaping due to this size change triggers a cascade of re-layout
+ // across the hierarchy where this label belongs to in a way that its size changes multiple
+ // times, but ending up with the original size it was already shaped for.
+ // This check prevents the catastrophic, freezing infinite cascade of re-layout.
+ if (lines_shaped_last_width != get_size().width) {
+ lines_dirty = true;
+ }
} break;
}
}
diff --git a/scene/gui/label.h b/scene/gui/label.h
index 2350525236..b80646810b 100644
--- a/scene/gui/label.h
+++ b/scene/gui/label.h
@@ -49,6 +49,8 @@ private:
bool uppercase = false;
bool lines_dirty = true;
+ int lines_shaped_last_width = -1;
+
bool dirty = true;
bool font_dirty = true;
RID text_rid;