浏览代码

Fix possible crash on loading save with invalid buildings, e.g. Mage
Guild 4 in towns without one

Ivan Savenko 9 月之前
父节点
当前提交
4ccd860b2f
共有 1 个文件被更改,包括 8 次插入0 次删除
  1. 8 0
      lib/mapObjects/CGTownInstance.cpp

+ 8 - 0
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<BuildingID, TownRewardableBuildingInstance*> CGTownInstance::convertOldBuildings(std::vector<TownRewardableBuildingInstance*> oldVector)