Skip to content

Commit 5682cc7

Browse files
committed
Avoid FlowContainer crash with TextureRect using EXPAND_FIT_* expand modes
When a FlowContainer had a TextureRect child using any of the EXPAND_FIT_* expand modes, it could crash when changing the FlowContainer's minimum size, or that of its children. This was due to the TextureRect resizing in FlowContainer::_resort, updating its minimum size, and triggering another _resort. If the TextureRect's minimum size changed in a way that caused any of the FlowContainer's children to be put on a different line, it could repeatedly cause _resort to be called again, moving the children back and forth between the old and new lines. This change is for FlowContainer::_resort to give a warning for TextureRects with EXPAND_FIT_* expand modes when multiple lines are used, and just keep the TextureRect size the same in that case. This is similar to the check added to AspectRatioContainer in godotengine#73396, but attempting to still support it in FlowContainer when possible. In the case where the TextureRect is forced to stay the same size, there may be some overlap between the FlowContainer's children, but should no longer crash.
1 parent 26d1577 commit 5682cc7

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

scene/gui/flow_container.cpp

+18-1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030

3131
#include "flow_container.h"
3232

33+
#include "scene/gui/texture_rect.h"
3334
#include "scene/theme/theme_db.h"
3435

3536
struct _LineData {
@@ -203,7 +204,23 @@ void FlowContainer::_resort() {
203204
}
204205
}
205206

206-
if (vertical) { /* VERTICAL */
207+
bool is_unsupported_texture_rect = false;
208+
if (lines_data.size() > 1) {
209+
TextureRect *trect = Object::cast_to<TextureRect>(child);
210+
if (trect) {
211+
TextureRect::ExpandMode mode = trect->get_expand_mode();
212+
if (mode == TextureRect::EXPAND_FIT_WIDTH || mode == TextureRect::EXPAND_FIT_WIDTH_PROPORTIONAL ||
213+
mode == TextureRect::EXPAND_FIT_HEIGHT || mode == TextureRect::EXPAND_FIT_HEIGHT_PROPORTIONAL) {
214+
is_unsupported_texture_rect = true;
215+
}
216+
}
217+
}
218+
219+
if (is_unsupported_texture_rect) {
220+
// Temporary fix for editor crash. Changing size of TextureRect with EXPAND_FIT_* ExpandModes can lead to infinite loop if child items are moved between lines.
221+
WARN_PRINT_ONCE("TextureRects with Fit Expand Modes are currently not supported inside FlowContainers with multiple lines");
222+
child_size = child->get_size();
223+
} else if (vertical) { /* VERTICAL */
207224
if (child->get_h_size_flags().has_flag(SIZE_FILL) || child->get_h_size_flags().has_flag(SIZE_SHRINK_CENTER) || child->get_h_size_flags().has_flag(SIZE_SHRINK_END)) {
208225
child_size.width = line_data.min_line_height;
209226
}

0 commit comments

Comments
 (0)