From 1e5362cb07e2b72384fd7538fe875b6ce8c18adb Mon Sep 17 00:00:00 2001 From: nordsoft Date: Sun, 2 Apr 2023 14:06:16 +0400 Subject: [PATCH] Fix crash with cutting random town --- lib/mapObjects/CGTownInstance.h | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/lib/mapObjects/CGTownInstance.h b/lib/mapObjects/CGTownInstance.h index 2eb63be11..2ccb9d2ea 100644 --- a/lib/mapObjects/CGTownInstance.h +++ b/lib/mapObjects/CGTownInstance.h @@ -256,15 +256,18 @@ public: h & townAndVis; BONUS_TREE_DESERIALIZATION_FIX - vstd::erase_if(builtBuildings, [this](BuildingID building) -> bool + if(town) { - if(!town->buildings.count(building) || !town->buildings.at(building)) + vstd::erase_if(builtBuildings, [this](BuildingID building) -> bool { - logGlobal->error("#1444-like issue in CGTownInstance::serialize. From town %s at %s removing the bogus builtBuildings item %s", name, pos.toString(), building); - return true; - } - return false; - }); + if(!town->buildings.count(building) || !town->buildings.at(building)) + { + logGlobal->error("#1444-like issue in CGTownInstance::serialize. From town %s at %s removing the bogus builtBuildings item %s", name, pos.toString(), building); + return true; + } + return false; + }); + } h & overriddenBuildings;