mirror of https://github.com/godotengine/godot
Handle changing ItemLists from signals
We make sure we don't touch the ItemList's items array after signals are emitted as a signal handler might change the item list, causing the index we had to be invalid. This fixes #100663
This commit is contained in:
parent
bdf625bd54
commit
32ef7306f4
|
|
@ -746,17 +746,8 @@ void ItemList::gui_input(const Ref<InputEvent> &p_event) {
|
|||
return;
|
||||
}
|
||||
|
||||
if (items[i].selectable && (!items[i].selected || allow_reselect) && select_mode != SELECT_TOGGLE) {
|
||||
select(i, select_mode == SELECT_SINGLE || !mb->is_command_or_control_pressed());
|
||||
|
||||
if (select_mode == SELECT_SINGLE) {
|
||||
emit_signal(SceneStringName(item_selected), i);
|
||||
} else {
|
||||
emit_signal(SNAME("multi_selected"), i, true);
|
||||
}
|
||||
}
|
||||
|
||||
if (items[i].selectable && select_mode == SELECT_TOGGLE) {
|
||||
if (select_mode == SELECT_TOGGLE) {
|
||||
if (items[i].selectable) {
|
||||
if (items[i].selected) {
|
||||
deselect(i);
|
||||
current = i;
|
||||
|
|
@ -767,6 +758,15 @@ void ItemList::gui_input(const Ref<InputEvent> &p_event) {
|
|||
emit_signal(SNAME("multi_selected"), i, true);
|
||||
}
|
||||
}
|
||||
} else if (items[i].selectable && (!items[i].selected || allow_reselect)) {
|
||||
select(i, select_mode == SELECT_SINGLE || !mb->is_command_or_control_pressed());
|
||||
|
||||
if (select_mode == SELECT_SINGLE) {
|
||||
emit_signal(SceneStringName(item_selected), i);
|
||||
} else {
|
||||
emit_signal(SNAME("multi_selected"), i, true);
|
||||
}
|
||||
}
|
||||
|
||||
emit_signal(SNAME("item_clicked"), i, get_local_mouse_position(), mb->get_button_index());
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue