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,7 +746,19 @@ void ItemList::gui_input(const Ref<InputEvent> &p_event) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (items[i].selectable && (!items[i].selected || allow_reselect) && select_mode != SELECT_TOGGLE) {
|
if (select_mode == SELECT_TOGGLE) {
|
||||||
|
if (items[i].selectable) {
|
||||||
|
if (items[i].selected) {
|
||||||
|
deselect(i);
|
||||||
|
current = i;
|
||||||
|
emit_signal(SNAME("multi_selected"), i, false);
|
||||||
|
} else {
|
||||||
|
select(i, false);
|
||||||
|
current = i;
|
||||||
|
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());
|
select(i, select_mode == SELECT_SINGLE || !mb->is_command_or_control_pressed());
|
||||||
|
|
||||||
if (select_mode == SELECT_SINGLE) {
|
if (select_mode == SELECT_SINGLE) {
|
||||||
|
|
@ -756,18 +768,6 @@ void ItemList::gui_input(const Ref<InputEvent> &p_event) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (items[i].selectable && select_mode == SELECT_TOGGLE) {
|
|
||||||
if (items[i].selected) {
|
|
||||||
deselect(i);
|
|
||||||
current = i;
|
|
||||||
emit_signal(SNAME("multi_selected"), i, false);
|
|
||||||
} else {
|
|
||||||
select(i, false);
|
|
||||||
current = i;
|
|
||||||
emit_signal(SNAME("multi_selected"), i, true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
emit_signal(SNAME("item_clicked"), i, get_local_mouse_position(), mb->get_button_index());
|
emit_signal(SNAME("item_clicked"), i, get_local_mouse_position(), mb->get_button_index());
|
||||||
|
|
||||||
if (mb->get_button_index() == MouseButton::LEFT && mb->is_double_click()) {
|
if (mb->get_button_index() == MouseButton::LEFT && mb->is_double_click()) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue