mirror of
https://github.com/vcmi/vcmi.git
synced 2025-05-13 22:06:58 +02:00
Fix server crash releated to active stack remove.
This commit is contained in:
parent
6cf220b882
commit
d1ec538d72
@ -5444,11 +5444,23 @@ void CGameHandler::runBattle()
|
|||||||
BattleSetActiveStack sas;
|
BattleSetActiveStack sas;
|
||||||
sas.stack = next->ID;
|
sas.stack = next->ID;
|
||||||
sendAndApply(&sas);
|
sendAndApply(&sas);
|
||||||
|
|
||||||
|
auto actionWasMade = [&]() -> bool
|
||||||
|
{
|
||||||
|
if(battleMadeAction.data)//active stack has made its action
|
||||||
|
return true;
|
||||||
|
if(battleResult.get())// battle is finished
|
||||||
|
return true;
|
||||||
|
return !next->alive();//active stack is dead
|
||||||
|
};
|
||||||
|
|
||||||
boost::unique_lock<boost::mutex> lock(battleMadeAction.mx);
|
boost::unique_lock<boost::mutex> lock(battleMadeAction.mx);
|
||||||
battleMadeAction.data = false;
|
battleMadeAction.data = false;
|
||||||
while (next->alive() && //next is invalid after sacrificing current stack :?
|
while(!actionWasMade())
|
||||||
(!battleMadeAction.data && !battleResult.get())) //active stack hasn't made its action and battle is still going
|
{
|
||||||
battleMadeAction.cond.wait(lock);
|
battleMadeAction.cond.wait(lock);
|
||||||
|
next = gs->curB->battleActiveStack(); //it may change while we wait
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user