From 4ccd860b2f6096b67610c7ae163cb8592c6fb813 Mon Sep 17 00:00:00 2001 From: Ivan Savenko Date: Fri, 3 Jan 2025 15:41:26 +0000 Subject: [PATCH] Fix possible crash on loading save with invalid buildings, e.g. Mage Guild 4 in towns without one --- lib/mapObjects/CGTownInstance.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/mapObjects/CGTownInstance.cpp b/lib/mapObjects/CGTownInstance.cpp index e9ca3c9cd..819d15723 100644 --- a/lib/mapObjects/CGTownInstance.cpp +++ b/lib/mapObjects/CGTownInstance.cpp @@ -1247,6 +1247,14 @@ void CGTownInstance::postDeserialize() setNodeType(CBonusSystemNode::TOWN); for(auto & building : rewardableBuildings) building.second->town = this; + + if (getFactionID().hasValue()) + { + vstd::erase_if(builtBuildings, [this](const BuildingID & buildID) + { + return getTown()->buildings.count(buildID) == 0; + }); + } } std::map CGTownInstance::convertOldBuildings(std::vector oldVector)