1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-11-24 08:32:34 +02:00

Nullkiller: fix crash when game ends

This commit is contained in:
Andrii Danylchenko 2021-05-16 14:57:05 +03:00 committed by Andrii Danylchenko
parent f0ceaf5852
commit 92ac78f87d

View File

@ -517,8 +517,17 @@ void VCAI::heroGotLevel(const CGHeroInstance * hero, PrimarySkill::PrimarySkill
{
LOG_TRACE_PARAMS(logAi, "queryID '%i'", queryID);
NET_EVENT_HANDLER;
status.addQuery(queryID, boost::str(boost::format("Hero %s got level %d") % hero->name % hero->level));
requestActionASAP([=](){ answerQuery(queryID, nullkiller->heroManager->selectBestSkill(hero, skills)); });
HeroPtr hPtr = hero;
requestActionASAP([=]()
{
if(hPtr.validAndSet())
{
answerQuery(queryID, nullkiller->heroManager->selectBestSkill(hPtr, skills));
}
});
}
void VCAI::commanderGotLevel(const CCommanderInstance * commander, std::vector<ui32> skills, QueryID queryID)
@ -566,6 +575,7 @@ void VCAI::showBlockingDialog(const std::string & text, const std::vector<Compon
answerQuery(askID, answer);
});
return;
}
@ -577,7 +587,8 @@ void VCAI::showBlockingDialog(const std::string & text, const std::vector<Compon
sel = components.size();
// TODO: Find better way to understand it is Chest of Treasures
if(components.size() == 2
if(hero.validAndSet()
&& components.size() == 2
&& components.front().id == Component::RESOURCE
&& nullkiller->heroManager->getHeroRole(hero) != HeroRole::MAIN)
{