Delay emitting pressed signals in PopupMenu
When processing items we may actually delete the item we're processing
in the callback for the signal. To avoid this, call the signal after
we're done processing the items. But before hiding the popupmenu itself.
Thanks to @reduz for writing the whole solution.
This fixes #19842
(cherry picked from commit fa7eac8a0d
)
This commit is contained in:
parent
5e25f40d83
commit
e4733c5fc4
|
@ -979,10 +979,8 @@ void PopupMenu::activate_item(int p_item) {
|
||||||
ERR_FAIL_INDEX(p_item, items.size());
|
ERR_FAIL_INDEX(p_item, items.size());
|
||||||
ERR_FAIL_COND(items[p_item].separator);
|
ERR_FAIL_COND(items[p_item].separator);
|
||||||
int id = items[p_item].ID >= 0 ? items[p_item].ID : p_item;
|
int id = items[p_item].ID >= 0 ? items[p_item].ID : p_item;
|
||||||
emit_signal("id_pressed", id);
|
|
||||||
emit_signal("index_pressed", p_item);
|
|
||||||
|
|
||||||
//hide all parent PopupMenue's
|
//hide all parent PopupMenus
|
||||||
Node *next = get_parent();
|
Node *next = get_parent();
|
||||||
PopupMenu *pop = Object::cast_to<PopupMenu>(next);
|
PopupMenu *pop = Object::cast_to<PopupMenu>(next);
|
||||||
while (pop) {
|
while (pop) {
|
||||||
|
@ -1006,16 +1004,23 @@ void PopupMenu::activate_item(int p_item) {
|
||||||
// Hides popup by default; unless otherwise specified
|
// Hides popup by default; unless otherwise specified
|
||||||
// by using set_hide_on_item_selection and set_hide_on_checkable_item_selection
|
// by using set_hide_on_item_selection and set_hide_on_checkable_item_selection
|
||||||
|
|
||||||
|
bool need_hide = true;
|
||||||
|
|
||||||
if (items[p_item].checkable_type) {
|
if (items[p_item].checkable_type) {
|
||||||
if (!hide_on_checkable_item_selection)
|
if (!hide_on_checkable_item_selection)
|
||||||
return;
|
need_hide = false;
|
||||||
} else if (0 < items[p_item].max_states) {
|
} else if (0 < items[p_item].max_states) {
|
||||||
if (!hide_on_multistate_item_selection)
|
if (!hide_on_multistate_item_selection)
|
||||||
return;
|
need_hide = false;
|
||||||
} else if (!hide_on_item_selection)
|
} else if (!hide_on_item_selection)
|
||||||
return;
|
need_hide = false;
|
||||||
|
|
||||||
hide();
|
emit_signal("id_pressed", id);
|
||||||
|
emit_signal("index_pressed", p_item);
|
||||||
|
|
||||||
|
if (need_hide) {
|
||||||
|
hide();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void PopupMenu::remove_item(int p_idx) {
|
void PopupMenu::remove_item(int p_idx) {
|
||||||
|
|
Loading…
Reference in New Issue