mirror of
https://github.com/vcmi/vcmi.git
synced 2024-11-28 08:48:48 +02:00
Fix potential BattleInfo destruction before usage
This commit is contained in:
parent
dcda359567
commit
4ccad9178e
@ -1465,9 +1465,7 @@ struct BattleResult : public Query
|
||||
exp[1] = 0;
|
||||
};
|
||||
void applyFirstCl(CClient *cl);
|
||||
void applyGs(CGameState *gs);
|
||||
|
||||
|
||||
EResult result;
|
||||
ui8 winner; //0 - attacker, 1 - defender, [2 - draw (should be possible?)]
|
||||
std::map<ui32,si32> casualties[2]; //first => casualties of attackers - map crid => number
|
||||
|
@ -1385,17 +1385,6 @@ DLL_LINKAGE void BattleUpdateGateState::applyGs(CGameState *gs)
|
||||
gs->curB->si.gateState = state;
|
||||
}
|
||||
|
||||
void BattleResult::applyGs(CGameState *gs)
|
||||
{
|
||||
for (auto & elem : gs->curB->stacks)
|
||||
delete elem;
|
||||
|
||||
for(int i = 0; i < 2; i++)
|
||||
gs->curB->battleGetArmyObject(i)->battle = nullptr;
|
||||
|
||||
gs->curB.dellNull();
|
||||
}
|
||||
|
||||
void BattleResultAccepted::applyGs(CGameState * gs)
|
||||
{
|
||||
for(auto * h : {hero1, hero2})
|
||||
@ -1425,7 +1414,9 @@ void BattleResultAccepted::applyGs(CGameState * gs)
|
||||
}
|
||||
|
||||
CBonusSystemNode::treeHasChanged();
|
||||
}
|
||||
}
|
||||
|
||||
gs->curB.dellNull();
|
||||
}
|
||||
|
||||
DLL_LINKAGE void BattleLogMessage::applyGs(CGameState *gs)
|
||||
|
@ -539,7 +539,15 @@ BattleInfo::BattleInfo():
|
||||
setNodeType(BATTLE);
|
||||
}
|
||||
|
||||
BattleInfo::~BattleInfo() = default;
|
||||
BattleInfo::~BattleInfo()
|
||||
{
|
||||
for (auto & elem : stacks)
|
||||
delete elem;
|
||||
|
||||
for(int i = 0; i < 2; i++)
|
||||
if(auto * _armyObj = battleGetArmyObject(i))
|
||||
_armyObj->battle = nullptr;
|
||||
}
|
||||
|
||||
int32_t BattleInfo::getActiveStackID() const
|
||||
{
|
||||
|
@ -2707,6 +2707,9 @@ void CGameHandler::startBattlePrimary(const CArmedInstance *army1, const CArmedI
|
||||
const CGHeroInstance *hero1, const CGHeroInstance *hero2, bool creatureBank,
|
||||
const CGTownInstance *town) //use hero=nullptr for no hero
|
||||
{
|
||||
if(gs->curB)
|
||||
gs->curB.dellNull();
|
||||
|
||||
engageIntoBattle(army1->tempOwner);
|
||||
engageIntoBattle(army2->tempOwner);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user