Browse Source

Merge pull request #94286 from aaronp64/flowcontainer_resort_crash

Avoid `FlowContainer` crash with `TextureRect` using EXPAND_FIT_* expand modes
Rémi Verschelde 1 year ago
parent
commit
3018178d3f
1 changed files with 18 additions and 1 deletions
  1. 18 1
      scene/gui/flow_container.cpp

+ 18 - 1
scene/gui/flow_container.cpp

@@ -30,6 +30,7 @@
 
 #include "flow_container.h"
 
+#include "scene/gui/texture_rect.h"
 #include "scene/theme/theme_db.h"
 
 struct _LineData {
@@ -203,7 +204,23 @@ void FlowContainer::_resort() {
 			}
 		}
 
-		if (vertical) { /* VERTICAL */
+		bool is_unsupported_texture_rect = false;
+		if (lines_data.size() > 1) {
+			TextureRect *trect = Object::cast_to<TextureRect>(child);
+			if (trect) {
+				TextureRect::ExpandMode mode = trect->get_expand_mode();
+				if (mode == TextureRect::EXPAND_FIT_WIDTH || mode == TextureRect::EXPAND_FIT_WIDTH_PROPORTIONAL ||
+						mode == TextureRect::EXPAND_FIT_HEIGHT || mode == TextureRect::EXPAND_FIT_HEIGHT_PROPORTIONAL) {
+					is_unsupported_texture_rect = true;
+				}
+			}
+		}
+
+		if (is_unsupported_texture_rect) {
+			// 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.
+			WARN_PRINT_ONCE("TextureRects with Fit Expand Modes are currently not supported inside FlowContainers with multiple lines");
+			child_size = child->get_size();
+		} else if (vertical) { /* VERTICAL */
 			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)) {
 				child_size.width = line_data.min_line_height;
 			}