From d1ec538d723e6d328f95ea02b14c753d7cd5f081 Mon Sep 17 00:00:00 2001 From: AlexVinS Date: Mon, 5 Oct 2015 21:09:00 +0300 Subject: [PATCH] Fix server crash releated to active stack remove. --- server/CGameHandler.cpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/server/CGameHandler.cpp b/server/CGameHandler.cpp index c58dec55d..4848c2dc4 100644 --- a/server/CGameHandler.cpp +++ b/server/CGameHandler.cpp @@ -5444,11 +5444,23 @@ void CGameHandler::runBattle() BattleSetActiveStack sas; sas.stack = next->ID; 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 lock(battleMadeAction.mx); battleMadeAction.data = false; - while (next->alive() && //next is invalid after sacrificing current stack :? - (!battleMadeAction.data && !battleResult.get())) //active stack hasn't made its action and battle is still going + while(!actionWasMade()) + { battleMadeAction.cond.wait(lock); + next = gs->curB->battleActiveStack(); //it may change while we wait + } } }