Skip to content

Commit

Permalink
Prevent infinite cascade of re-layout after label text reshaping
Browse files Browse the repository at this point in the history
  • Loading branch information
RandomShaper committed Jan 17, 2023
1 parent 629796c commit ed8c5cd
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
9 changes: 8 additions & 1 deletion scene/gui/label.cpp
Expand Up @@ -222,6 +222,7 @@ void Label::_shape() {
}
}
lines_dirty = false;
lines_shaped_last_width = get_size().width;
}

_update_visible();
Expand Down Expand Up @@ -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;
}
}
Expand Down
2 changes: 2 additions & 0 deletions scene/gui/label.h
Expand Up @@ -49,6 +49,8 @@ class Label : public Control {
bool uppercase = false;

bool lines_dirty = true;
int lines_shaped_last_width = -1;

bool dirty = true;
bool font_dirty = true;
RID text_rid;
Expand Down

0 comments on commit ed8c5cd

Please sign in to comment.