1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-08-13 19:54:17 +02:00

Changes related to #1444 — fixing affected savegames, assert to detect when things go wrong.

This commit is contained in:
Michał W. Urbańczyk
2013-09-27 15:20:42 +00:00
parent d4a8e90460
commit 0e5a59e2a5
5 changed files with 18 additions and 2 deletions

View File

@@ -1369,6 +1369,10 @@ void CGameState::init(StartInfo * si)
}
}
//Early check for #1444-like problems
for(auto building : vti->builtBuildings)
assert(vti->town->buildings[building]);
//town events
for(CCastleEvent &ev : vti->events)
{

View File

@@ -2685,7 +2685,6 @@ void CGTownInstance::battleFinished(const CGHeroInstance *hero, const BattleResu
}
}
bool CGVisitableOPH::wasVisited (const CGHeroInstance * h) const
{
return vstd::contains(visitors, h->id);

View File

@@ -617,6 +617,17 @@ public:
h & town & townAndVis;
BONUS_TREE_DESERIALIZATION_FIX
vstd::erase_if(builtBuildings, [this](BuildingID building) -> bool
{
if(!town->buildings.count(building) || !town->buildings.at(building))
{
logGlobal->errorStream() << boost::format("#1444-like issue in CGTownInstance::serialize. From town %s at %s removing the bogus builtBuildings item %s")
% name % pos % building;
return true;
}
return false;
});
}
//////////////////////////////////////////////////////////////////////////

View File

@@ -205,7 +205,7 @@ public:
//Fix #1444 corrupted save
while(auto badElem = vstd::tryFindIf(buildings, findNull))
{
std::cout << "#1444-like bug encountered, fixing buildings list by removing bogus entry " << badElem->first << " from " << faction->name << std::endl;
logGlobal->errorStream() << "#1444-like bug encountered in CTown::serialize, fixing buildings list by removing bogus entry " << badElem->first << " from " << faction->name;
buildings.erase(badElem->first);
}
}

View File

@@ -13,6 +13,7 @@
#include "CCreatureHandler.h"
#include "CGameState.h"
#include "BattleState.h"
#include "CTownHandler.h"
#undef min
#undef max
@@ -448,6 +449,7 @@ DLL_LINKAGE void NewStructures::applyGs( CGameState *gs )
CGTownInstance *t = gs->getTown(tid);
for(const auto & id : bid)
{
assert(t->town->buildings[id]);
t->builtBuildings.insert(id);
}
t->builded = builded;