summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRĂ©mi Verschelde <rverschelde@gmail.com>2019-10-06 20:50:18 +0200
committerGitHub <noreply@github.com>2019-10-06 20:50:18 +0200
commitc8f6661459aeea683c662ed6bb15d689b1a7568b (patch)
treea999a7a26d2a5b0c8bd1093a11feac5aedd73000
parent8543cc2ff9e01274ccedee9eeddee8062cd4264a (diff)
parent17344337a9b15cc77a62a59cc3f5323351831415 (diff)
Merge pull request #32569 from qarmin/fix_control_crash
Fix crash in Control functions
-rw-r--r--scene/gui/control.cpp26
-rw-r--r--scene/gui/file_dialog.cpp2
-rw-r--r--scene/gui/item_list.cpp1
-rw-r--r--scene/gui/rich_text_label.cpp5
4 files changed, 34 insertions, 0 deletions
diff --git a/scene/gui/control.cpp b/scene/gui/control.cpp
index fc67b28095..fafbcf0c55 100644
--- a/scene/gui/control.cpp
+++ b/scene/gui/control.cpp
@@ -1412,6 +1412,9 @@ void Control::_size_changed() {
}
void Control::set_anchor(Margin p_margin, float p_anchor, bool p_keep_margin, bool p_push_opposite_anchor) {
+
+ ERR_FAIL_INDEX((int)p_margin, 4);
+
Rect2 parent_rect = get_parent_anchorable_rect();
float parent_range = (p_margin == MARGIN_LEFT || p_margin == MARGIN_RIGHT) ? parent_rect.size.x : parent_rect.size.y;
float previous_margin_pos = data.margin[p_margin] + data.anchor[p_margin] * parent_range;
@@ -1456,6 +1459,9 @@ void Control::set_anchor_and_margin(Margin p_margin, float p_anchor, float p_pos
}
void Control::set_anchors_preset(LayoutPreset p_preset, bool p_keep_margins) {
+
+ ERR_FAIL_INDEX((int)p_preset, 16);
+
//Left
switch (p_preset) {
case PRESET_TOP_LEFT:
@@ -1570,6 +1576,10 @@ void Control::set_anchors_preset(LayoutPreset p_preset, bool p_keep_margins) {
}
void Control::set_margins_preset(LayoutPreset p_preset, LayoutPresetMode p_resize_mode, int p_margin) {
+
+ ERR_FAIL_INDEX((int)p_preset, 16);
+ ERR_FAIL_INDEX((int)p_resize_mode, 4);
+
// Calculate the size if the node is not resized
Size2 min_size = get_minimum_size();
Size2 new_size = get_size();
@@ -1704,6 +1714,8 @@ void Control::set_anchors_and_margins_preset(LayoutPreset p_preset, LayoutPreset
float Control::get_anchor(Margin p_margin) const {
+ ERR_FAIL_INDEX_V(int(p_margin), 4, 0.0);
+
return data.anchor[p_margin];
}
@@ -1720,6 +1732,8 @@ void Control::_change_notify_margins() {
void Control::set_margin(Margin p_margin, float p_value) {
+ ERR_FAIL_INDEX((int)p_margin, 4);
+
data.margin[p_margin] = p_value;
_size_changed();
}
@@ -1740,6 +1754,8 @@ void Control::set_end(const Size2 &p_point) {
float Control::get_margin(Margin p_margin) const {
+ ERR_FAIL_INDEX_V((int)p_margin, 4, 0);
+
return data.margin[p_margin];
}
@@ -1951,6 +1967,8 @@ void Control::add_constant_override(const StringName &p_name, int p_constant) {
void Control::set_focus_mode(FocusMode p_focus_mode) {
+ ERR_FAIL_INDEX((int)p_focus_mode, 3);
+
if (is_inside_tree() && p_focus_mode == FOCUS_NONE && data.focus_mode != FOCUS_NONE && has_focus())
release_focus();
@@ -2298,6 +2316,8 @@ Control *Control::make_custom_tooltip(const String &p_text) const {
void Control::set_default_cursor_shape(CursorShape p_shape) {
+ ERR_FAIL_INDEX(int(p_shape), CURSOR_MAX);
+
data.default_cursor = p_shape;
}
@@ -2358,6 +2378,8 @@ NodePath Control::get_focus_previous() const {
Control *Control::_get_focus_neighbour(Margin p_margin, int p_count) {
+ ERR_FAIL_INDEX_V((int)p_margin, 4, NULL);
+
if (p_count >= MAX_NEIGHBOUR_SEARCH_COUNT)
return NULL;
if (!data.focus_neighbour[p_margin].is_empty()) {
@@ -2760,6 +2782,8 @@ bool Control::is_clipping_contents() {
void Control::set_h_grow_direction(GrowDirection p_direction) {
+ ERR_FAIL_INDEX((int)p_direction, 3);
+
data.h_grow = p_direction;
_size_changed();
}
@@ -2771,6 +2795,8 @@ Control::GrowDirection Control::get_h_grow_direction() const {
void Control::set_v_grow_direction(GrowDirection p_direction) {
+ ERR_FAIL_INDEX((int)p_direction, 3);
+
data.v_grow = p_direction;
_size_changed();
}
diff --git a/scene/gui/file_dialog.cpp b/scene/gui/file_dialog.cpp
index 9bc593ea3b..24c046457b 100644
--- a/scene/gui/file_dialog.cpp
+++ b/scene/gui/file_dialog.cpp
@@ -637,6 +637,8 @@ bool FileDialog::is_mode_overriding_title() const {
void FileDialog::set_mode(Mode p_mode) {
+ ERR_FAIL_INDEX((int)p_mode, 5);
+
mode = p_mode;
switch (mode) {
diff --git a/scene/gui/item_list.cpp b/scene/gui/item_list.cpp
index a3bc68ffcd..4d06bee0d4 100644
--- a/scene/gui/item_list.cpp
+++ b/scene/gui/item_list.cpp
@@ -430,6 +430,7 @@ ItemList::SelectMode ItemList::get_select_mode() const {
void ItemList::set_icon_mode(IconMode p_mode) {
+ ERR_FAIL_INDEX((int)p_mode, 2);
icon_mode = p_mode;
update();
shape_changed = true;
diff --git a/scene/gui/rich_text_label.cpp b/scene/gui/rich_text_label.cpp
index c5330c78e1..42cb89b2d6 100644
--- a/scene/gui/rich_text_label.cpp
+++ b/scene/gui/rich_text_label.cpp
@@ -143,6 +143,8 @@ Rect2 RichTextLabel::_get_text_rect() {
int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int &y, int p_width, int p_line, ProcessMode p_mode, const Ref<Font> &p_base_font, const Color &p_base_color, const Color &p_font_color_shadow, bool p_shadow_as_outline, const Point2 &shadow_ofs, const Point2i &p_click_pos, Item **r_click_item, int *r_click_char, bool *r_outside, int p_char_count) {
+ ERR_FAIL_INDEX_V((int)p_mode, 3, 0);
+
RID ci;
if (r_outside)
*r_outside = false;
@@ -1416,6 +1418,9 @@ bool RichTextLabel::_find_strikethrough(Item *p_item) {
}
bool RichTextLabel::_find_by_type(Item *p_item, ItemType p_type) {
+
+ ERR_FAIL_INDEX_V((int)p_type, 19, false);
+
Item *item = p_item;
while (item) {