1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-09-16 09:26:28 +02:00

Made player interface tolerant to active stack removal.

This commit is contained in:
AlexVinS
2015-10-06 03:46:35 +03:00
parent d042b08682
commit f99bf099ca
6 changed files with 27 additions and 8 deletions

View File

@@ -772,7 +772,8 @@ BattleAction CPlayerInterface::activeStack(const CStack * stack) //called when i
{
THREAD_CREATED_BY_CLIENT;
logGlobal->traceStream() << "Awaiting command for " << stack->nodeName();
auto stackId = stack->ID;
auto stackName = stack->nodeName();
if(autofightingAI)
{
if(isAutoFightOn)
@@ -806,17 +807,27 @@ BattleAction CPlayerInterface::activeStack(const CStack * stack) //called when i
while(!b->givenCommand->data)
{
b->givenCommand->cond.wait(lock);
if(!battleInt) //batle ended while we were waiting for movement (eg. because of spell)
if(!battleInt) //battle ended while we were waiting for movement (eg. because of spell)
throw boost::thread_interrupted(); //will shut the thread peacefully
}
//tidy up
BattleAction ret = *(b->givenCommand->data);
//todo: remove this evil hack
//dirty evil hack...
//if active stack was changed, new thread was started for new active stack but we will receive notification too
//we need check that givenCommand is for our stack (use ID as stack object may be even destroyed)
if(stackId != ret.stackNumber)
{
logGlobal->traceStream() << "Interrupted command for " << stackName;
throw boost::thread_interrupted();
}
delete b->givenCommand->data;
b->givenCommand->data = nullptr;
//return command
logGlobal->traceStream() << "Giving command for " << stack->nodeName();
logGlobal->traceStream() << "Giving command for " << stackName;
return ret;
}