diff --git a/CHANGELOG.md b/CHANGELOG.md index 52474151..93fe75e6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,10 @@ The **"Breaking Changes"** listed below are changes that have been made in the d ### Added - Add optional support for Poryscript script files via the `use_poryscript` config option. +### Fixed +- Fix index-out-of-bounds crash when deleting the last event in an event type group. + + ## [2.0.0] - 2019-10-16 ### Breaking Changes - Accomodate event object graphics pointer table being explicitly indexed. From changes introduced in commits [cdae0c1444bed98e652c87dc3e3edcecacfef8be](https://github.com/pret/pokeemerald/commit/cdae0c1444bed98e652c87dc3e3edcecacfef8be) and [0e8ccfc4fd3544001f4c25fafd401f7558bdefba](https://github.com/pret/pokeruby/commit/0e8ccfc4fd3544001f4c25fafd401f7558bdefba). 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);