1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-01-12 02:28:11 +02:00

Not crash when asking callback about requirements for not existing building, fixing #1444 corrupted saves (for testing).

This commit is contained in:
Michał W. Urbańczyk 2013-09-07 16:57:31 +00:00
parent 76c77d58f6
commit 141c1a9854
2 changed files with 13 additions and 2 deletions

View File

@ -198,6 +198,15 @@ public:
{
h & names & faction & creatures & dwellings & dwellingNames & buildings & hordeLvl & mageLevel
& primaryRes & warMachine & clientInfo & moatDamage;
//Fix #1444 corrupted save
while(auto badElem = vstd::tryFindIf(buildings, [](const std::pair<BuildingID, ConstTransitivePtr<CBuilding>> &building)
{ return building.second == nullptr; }))
{
std::cout << "#1444-like bug encountered, fixing buildings list by removing bogus entry " << badElem->first << " from " << faction->name << std::endl;
buildings.erase(badElem->first);
}
}
};

View File

@ -567,10 +567,11 @@ EBuildingState::EBuildingState CGameInfoCallback::canBuildStructure( const CGTow
{
ERROR_RET_VAL_IF(!canGetFullInfo(t), "Town is not owned!", EBuildingState::TOWN_NOT_OWNED);
if(!t->town->buildings.count(ID))
return EBuildingState::BUILDING_ERROR;
const CBuilding * pom = t->town->buildings[ID];
if(!pom)
return EBuildingState::BUILDING_ERROR;
if(t->hasBuilt(ID)) //already built
return EBuildingState::ALREADY_PRESENT;
@ -632,6 +633,7 @@ EBuildingState::EBuildingState CGameInfoCallback::canBuildStructure( const CGTow
std::set<BuildingID> CGameInfoCallback::getBuildingRequiments( const CGTownInstance *t, BuildingID ID )
{
ERROR_RET_VAL_IF(!canGetFullInfo(t), "Town is not owned!", std::set<BuildingID>());
ERROR_RET_VAL_IF(!t->town->buildings.count(ID), "No such building!", std::set<BuildingID>());
std::set<int> used;
used.insert(ID);