mirror of
https://github.com/vcmi/vcmi.git
synced 2025-07-05 00:49:09 +02:00
Prevent crashing when pressing auto-combat button on enemy turn
This commit is contained in:
@ -663,15 +663,11 @@ void BattleInterface::requestAutofightingAIToTakeAction()
|
|||||||
|
|
||||||
boost::thread aiThread([&]()
|
boost::thread aiThread([&]()
|
||||||
{
|
{
|
||||||
auto ba = std::make_unique<BattleAction>(curInt->autofightingAI->activeStack(stacksController->getActiveStack()));
|
|
||||||
|
|
||||||
if(curInt->cb->battleIsFinished())
|
if(curInt->cb->battleIsFinished())
|
||||||
{
|
{
|
||||||
return; // battle finished with spellcast
|
return; // battle finished with spellcast
|
||||||
}
|
}
|
||||||
|
|
||||||
if (curInt->isAutoFightOn)
|
|
||||||
{
|
|
||||||
if (tacticsMode)
|
if (tacticsMode)
|
||||||
{
|
{
|
||||||
// Always end tactics mode. Player interface is blocked currently, so it's not possible that
|
// Always end tactics mode. Player interface is blocked currently, so it's not possible that
|
||||||
@ -683,14 +679,15 @@ void BattleInterface::requestAutofightingAIToTakeAction()
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
const CStack* activeStack = stacksController->getActiveStack();
|
||||||
|
|
||||||
|
// If enemy is moving, activeStack can be null
|
||||||
|
if (activeStack)
|
||||||
|
{
|
||||||
|
auto ba = std::make_unique<BattleAction>(curInt->autofightingAI->activeStack(activeStack));
|
||||||
givenCommand.setn(ba.release());
|
givenCommand.setn(ba.release());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
boost::unique_lock<boost::recursive_mutex> un(*CPlayerInterface::pim);
|
|
||||||
activateStack();
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
aiThread.detach();
|
aiThread.detach();
|
||||||
|
Reference in New Issue
Block a user