Guard against index out of bounds when deleting last event in group

This commit is contained in:
Marcus Huderle 2019-11-02 18:20:41 -05:00
parent 631896a708
commit 654b788937

View file

@ -1785,11 +1785,15 @@ void MainWindow::on_toolButton_deleteObject_clicked()
for (DraggablePixmapItem *item : *editor->selected_events) {
QString event_group = item->event->get("event_group_type");
int index = editor->map->events.value(event_group).indexOf(item->event);
// Get the index for the event that should be selected after this event has been deleted.
// If it's at the end of the list, select the previous event, otherwise select the next one.
if (index != editor->map->events.value(event_group).size() - 1)
index++;
else
index--;
Event *event = editor->map->events.value(event_group).at(index);
Event *event = nullptr;
if (index >= 0)
event = editor->map->events.value(event_group).at(index);
if (event_group != "heal_event_group") {
for (QGraphicsItem *child : editor->events_group->childItems()) {
DraggablePixmapItem *event_item = static_cast<DraggablePixmapItem *>(child);