1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-14 10:12:59 +02:00

fix crash on heroRoles.clear()

This commit is contained in:
MichalZr6 2024-08-28 15:16:33 +02:00
parent 7ae7c13964
commit ca3d81f047

View File

@ -126,20 +126,23 @@ void HeroManager::update()
}
std::sort(myHeroes.begin(), myHeroes.end(), scoreSort);
heroRoles.clear();
std::map<HeroPtr, HeroRole> newHeroRoles;
for(auto hero : myHeroes)
{
if(hero->patrol.patrolling)
{
heroRoles[hero] = HeroRole::MAIN;
newHeroRoles[hero] = HeroRole::MAIN;
}
else
{
heroRoles[hero] = (globalMainCount--) > 0 ? HeroRole::MAIN : HeroRole::SCOUT;
newHeroRoles[hero] = (globalMainCount--) > 0 ? HeroRole::MAIN : HeroRole::SCOUT;
}
}
heroRoles = std::move(newHeroRoles);
for(auto hero : myHeroes)
{
logAi->trace("Hero %s has role %s", hero->getNameTranslated(), heroRoles[hero] == HeroRole::MAIN ? "main" : "scout");