From ca3d81f047962dcee38813d8d8b2e3c7381e3214 Mon Sep 17 00:00:00 2001 From: MichalZr6 Date: Wed, 28 Aug 2024 15:16:33 +0200 Subject: [PATCH] fix crash on heroRoles.clear() --- AI/Nullkiller/Analyzers/HeroManager.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/AI/Nullkiller/Analyzers/HeroManager.cpp b/AI/Nullkiller/Analyzers/HeroManager.cpp index 44b66b46b..a67fd8ebc 100644 --- a/AI/Nullkiller/Analyzers/HeroManager.cpp +++ b/AI/Nullkiller/Analyzers/HeroManager.cpp @@ -126,20 +126,23 @@ void HeroManager::update() } std::sort(myHeroes.begin(), myHeroes.end(), scoreSort); - heroRoles.clear(); + + std::map 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");