1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-11-06 09:09:40 +02:00

Fix crash with objects belonging players without state

This commit is contained in:
nordsoft
2022-11-06 03:26:13 +04:00
parent ae1d2c50e2
commit 0f35082024
15 changed files with 92 additions and 88 deletions

View File

@@ -1146,7 +1146,7 @@ std::string CGTownInstance::nodeName() const
void CGTownInstance::deserializationFix()
{
attachTo(&townAndVis);
attachTo(townAndVis);
//Hero is already handled by CGameState::attachArmedObjects
@@ -1216,8 +1216,8 @@ void CGTownInstance::setVisitingHero(CGHeroInstance *h)
{
PlayerState *p = cb->gameState()->getPlayerState(h->tempOwner);
assert(p);
h->detachFrom(p);
h->attachTo(&townAndVis);
h->detachFrom(*p);
h->attachTo(townAndVis);
visitingHero = h;
h->visitedTown = this;
h->inTownGarrison = false;
@@ -1226,8 +1226,8 @@ void CGTownInstance::setVisitingHero(CGHeroInstance *h)
{
PlayerState *p = cb->gameState()->getPlayerState(visitingHero->tempOwner);
visitingHero->visitedTown = nullptr;
visitingHero->detachFrom(&townAndVis);
visitingHero->attachTo(p);
visitingHero->detachFrom(townAndVis);
visitingHero->attachTo(*p);
visitingHero = nullptr;
}
}
@@ -1239,8 +1239,8 @@ void CGTownInstance::setGarrisonedHero(CGHeroInstance *h)
{
PlayerState *p = cb->gameState()->getPlayerState(h->tempOwner);
assert(p);
h->detachFrom(p);
h->attachTo(this);
h->detachFrom(*p);
h->attachTo(*this);
garrisonHero = h;
h->visitedTown = this;
h->inTownGarrison = true;
@@ -1250,8 +1250,8 @@ void CGTownInstance::setGarrisonedHero(CGHeroInstance *h)
PlayerState *p = cb->gameState()->getPlayerState(garrisonHero->tempOwner);
garrisonHero->visitedTown = nullptr;
garrisonHero->inTownGarrison = false;
garrisonHero->detachFrom(this);
garrisonHero->attachTo(p);
garrisonHero->detachFrom(*this);
garrisonHero->attachTo(*p);
garrisonHero = nullptr;
}
updateMoraleBonusFromArmy(); //avoid giving morale bonus for same army twice
@@ -1290,9 +1290,9 @@ int CGTownInstance::getTownLevel() const
return level;
}
CBonusSystemNode * CGTownInstance::whatShouldBeAttached()
CBonusSystemNode & CGTownInstance::whatShouldBeAttached()
{
return &townAndVis;
return townAndVis;
}
const CArmedInstance * CGTownInstance::getUpperArmy() const