From 40adedef346e9f818016b26c5a71e3bebde28021 Mon Sep 17 00:00:00 2001 From: GriffinR Date: Mon, 23 Dec 2024 11:42:57 -0500 Subject: [PATCH] Fix editor's map/layout clearing if a map/layout fails to load --- src/editor.cpp | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/editor.cpp b/src/editor.cpp index d0a122ec..c22068d2 100644 --- a/src/editor.cpp +++ b/src/editor.cpp @@ -1242,10 +1242,10 @@ QString Editor::getMovementPermissionText(uint16_t collision, uint16_t elevation void Editor::unsetMap() { // disconnect previous map's signals so they are not firing // multiple times if set again in the future - if (map) { - map->pruneEditHistory(); - map->disconnect(this); - for (auto connection : map->getConnections()) + if (this->map) { + this->map->pruneEditHistory(); + this->map->disconnect(this); + for (const auto &connection : this->map->getConnections()) disconnectMapConnection(connection); } clearMapConnections(); @@ -1258,13 +1258,12 @@ bool Editor::setMap(QString map_name) { return false; } - unsetMap(); - Map *loadedMap = project->loadMap(map_name); if (!loadedMap) { return false; } + unsetMap(); this->map = loadedMap; setLayout(map->layout()->id); @@ -1291,13 +1290,17 @@ bool Editor::setLayout(QString layoutId) { return false; } - this->layout = this->project->loadLayout(layoutId); + Layout *loadedLayout = this->project->loadLayout(layoutId); + if (!loadedLayout) { + return false; + } + this->layout = loadedLayout; if (!displayLayout()) { return false; } - editGroup.addStack(&layout->editHistory); + editGroup.addStack(&this->layout->editHistory); map_ruler->setMapDimensions(QSize(this->layout->getWidth(), this->layout->getHeight())); connect(this->layout, &Layout::layoutDimensionsChanged, map_ruler, &MapRuler::setMapDimensions);