Merge pull request #34374 from KoBeWi/thinking_out_of_the_loop

Prevent infinite loop when focus_next is invisible
This commit is contained in:
Rémi Verschelde 2019-12-16 08:24:49 +01:00 committed by GitHub
commit b72e4079f3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -2012,14 +2012,15 @@ Control *Control::find_next_valid_focus() const {
if (!data.focus_next.is_empty()) { if (!data.focus_next.is_empty()) {
Node *n = get_node(data.focus_next); Node *n = get_node(data.focus_next);
Control *c;
if (n) { if (n) {
from = Object::cast_to<Control>(n); c = Object::cast_to<Control>(n);
ERR_FAIL_COND_V_MSG(!from, NULL, "Next focus node is not a control: " + n->get_name() + "."); ERR_FAIL_COND_V_MSG(!c, NULL, "Next focus node is not a control: " + n->get_name() + ".");
} else { } else {
return NULL; return NULL;
} }
if (from->is_visible() && from->get_focus_mode() != FOCUS_NONE) if (c->is_visible() && c->get_focus_mode() != FOCUS_NONE)
return from; return c;
} }
// find next child // find next child
@ -2102,14 +2103,15 @@ Control *Control::find_prev_valid_focus() const {
if (!data.focus_prev.is_empty()) { if (!data.focus_prev.is_empty()) {
Node *n = get_node(data.focus_prev); Node *n = get_node(data.focus_prev);
Control *c;
if (n) { if (n) {
from = Object::cast_to<Control>(n); c = Object::cast_to<Control>(n);
ERR_FAIL_COND_V_MSG(!from, NULL, "Previous focus node is not a control: " + n->get_name() + "."); ERR_FAIL_COND_V_MSG(!c, NULL, "Previous focus node is not a control: " + n->get_name() + ".");
} else { } else {
return NULL; return NULL;
} }
if (from->is_visible() && from->get_focus_mode() != FOCUS_NONE) if (c->is_visible() && c->get_focus_mode() != FOCUS_NONE)
return from; return c;
} }
// find prev child // find prev child