From 93661bbe1b05953e398007158ceafb78d23b6183 Mon Sep 17 00:00:00 2001 From: Marcus Huderle Date: Mon, 18 May 2020 17:24:37 -0500 Subject: [PATCH] Fix crash when painting an event when no existing events exist for the map --- src/editor.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/editor.cpp b/src/editor.cpp index 0fc4e49c..b95b1749 100644 --- a/src/editor.cpp +++ b/src/editor.cpp @@ -1070,11 +1070,15 @@ void Editor::mouseEvent_map(QGraphicsSceneMouseEvent *event, MapPixmapItem *item // Left-clicking while in paint mode will add a new event of the // type of the first currently selected events. // Disallow adding heal locations, deleting them is not possible yet - QString eventType = this->selected_events->first()->event->get("event_type"); - if (eventType != "event_heal_location") { + QString eventType = EventType::Object; + if (this->selected_events->size() > 0) + eventType = this->selected_events->first()->event->get("event_type"); + + if (eventType != EventType::HealLocation) { DraggablePixmapItem * newEvent = addNewEvent(eventType); if (newEvent) { newEvent->move(x, y); + emit objectsChanged(); selectMapEvent(newEvent, false); } } @@ -1872,7 +1876,7 @@ DraggablePixmapItem* Editor::addNewEvent(QString event_type) { if (project && map && !event_type.isEmpty()) { Event *event = Event::createNewEvent(event_type, map->name, project); event->put("map_name", map->name); - if (event_type == "event_heal_location") { + if (event_type == EventType::HealLocation) { HealLocation hl = HealLocation::fromEvent(event); project->healLocations.append(hl); event->put("index", project->healLocations.length());