From 654b788937efee7d79f4542cb451c0f4d8017976 Mon Sep 17 00:00:00 2001 From: Marcus Huderle Date: Sat, 2 Nov 2019 18:20:41 -0500 Subject: [PATCH] Guard against index out of bounds when deleting last event in group --- src/mainwindow.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 81882671..8bda04e5 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -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(child);