Skip to content

Commit

Permalink
Fix crash with AspectRatioContainer and TextureRect
Browse files Browse the repository at this point in the history
  • Loading branch information
KoBeWi committed Feb 16, 2023
1 parent f2aae8f commit a12921c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
3 changes: 2 additions & 1 deletion doc/classes/TextureRect.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@
<link title="3D Voxel Demo">https://godotengine.org/asset-library/asset/676</link>
</tutorials>
<members>
<member name="expand_mode" type="int" setter="set_expand_mode" getter="get_expand_mode" enum="TextureRect.ExpandMode" default="0">
<member name="expand_mode" type="int" setter="set_expand_mode" getter="get_expand_mode" enum="TextureRect.ExpandMode" default="0" is_experimental="true">
Defines how minimum size is determined based on the texture's size. See [enum ExpandMode] for options.
[b]Note:[/b] Using [constant EXPAND_FIT_WIDTH], [constant EXPAND_FIT_WIDTH_PROPORTIONAL], [constant EXPAND_FIT_HEIGHT] or [constant EXPAND_FIT_HEIGHT_PROPORTIONAL] may result in unstable behavior in some containers. This functionality is being re-evaluated and will change in the future.
</member>
<member name="flip_h" type="bool" setter="set_flip_h" getter="is_flipped_h" default="false">
If [code]true[/code], texture is flipped horizontally.
Expand Down
12 changes: 12 additions & 0 deletions scene/gui/aspect_ratio_container.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@

#include "aspect_ratio_container.h"

#include "scene/gui/texture_rect.h"

Size2 AspectRatioContainer::get_minimum_size() const {
Size2 ms;
for (int i = 0; i < get_child_count(); i++) {
Expand Down Expand Up @@ -113,6 +115,16 @@ void AspectRatioContainer::_notification(int p_what) {
if (c->is_set_as_top_level()) {
continue;
}

// Temporary fix for editor crash.
TextureRect *trect = Object::cast_to<TextureRect>(c);
if (trect) {
if (trect->get_expand_mode() == TextureRect::EXPAND_FIT_WIDTH_PROPORTIONAL || trect->get_expand_mode() == TextureRect::EXPAND_FIT_HEIGHT_PROPORTIONAL) {
WARN_PRINT_ONCE("Proportional TextureRect is currently not supported inside AspectRatioContainer");
continue;
}
}

Size2 child_minsize = c->get_combined_minimum_size();
Size2 child_size = Size2(ratio, 1.0);
float scale_factor = 1.0;
Expand Down

0 comments on commit a12921c

Please sign in to comment.