mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-24 22:14:36 +02:00
Fix memory corruption with a draw; race in setBattleResult()
This commit is contained in:
parent
7185890723
commit
6849ff846c
@ -124,6 +124,11 @@ static inline double distance(int3 a, int3 b)
|
||||
}
|
||||
static void giveExp(BattleResult &r)
|
||||
{
|
||||
if(r.winner > 1)
|
||||
{
|
||||
// draw
|
||||
return;
|
||||
}
|
||||
r.exp[0] = 0;
|
||||
r.exp[1] = 0;
|
||||
for(auto i = r.casualties[!r.winner].begin(); i!=r.casualties[!r.winner].end(); i++)
|
||||
@ -5679,16 +5684,18 @@ void CGameHandler::giveHeroNewArtifact(const CGHeroInstance *h, const CArtifact
|
||||
|
||||
void CGameHandler::setBattleResult(BattleResult::EResult resultType, int victoriusSide)
|
||||
{
|
||||
if(battleResult.get())
|
||||
boost::unique_lock<boost::mutex> guard(battleResult.mx);
|
||||
if(battleResult.data)
|
||||
{
|
||||
complain("There is already set result?");
|
||||
complain((boost::format("The battle result has been already set (to %d, asked to %d)")
|
||||
% battleResult.data->result % resultType).str());
|
||||
return;
|
||||
}
|
||||
auto br = new BattleResult;
|
||||
br->result = resultType;
|
||||
br->winner = victoriusSide; //surrendering side loses
|
||||
gs->curB->calculateCasualties(br->casualties);
|
||||
battleResult.set(br);
|
||||
battleResult.data = br;
|
||||
}
|
||||
|
||||
void CGameHandler::commitPackage( CPackForClient *pack )
|
||||
|
Loading…
Reference in New Issue
Block a user