Ver Fonte

Nullkiller: fix crash

Andrii Danylchenko há 3 anos atrás
pai
commit
02b2f35143

+ 1 - 1
AI/Nullkiller/Behaviors/DefenceBehavior.cpp

@@ -65,7 +65,7 @@ void DefenceBehavior::evaluateDefence(Goals::TGoalVec & tasks, const CGTownInsta
 	{
 		if(!ai->nullkiller->isHeroLocked(town->garrisonHero.get()))
 		{
-			if(!town->visitingHero)
+			if(!town->visitingHero && cb->getHeroesInfo().size() < GameConstants::MAX_HEROES_PER_PLAYER)
 			{
 				tasks.push_back(Goals::sptr(Goals::ExchangeSwapTownHeroes(town, nullptr).setpriority(5)));
 			}

+ 12 - 3
AI/Nullkiller/Goals/ExchangeSwapTownHeroes.cpp

@@ -42,13 +42,22 @@ void ExchangeSwapTownHeroes::accept(AIGateway * ai)
 {
 	if(!garrisonHero)
 	{
-		if(!town->garrisonHero)
+		auto currentGarrisonHero = town->garrisonHero;
+		
+		if(!currentGarrisonHero)
 			throw cannotFulfillGoalException("Invalid configuration. There is no hero in town garrison.");
 		
 		cb->swapGarrisonHero(town);
+
+		if(currentGarrisonHero.get() != town->visitingHero.get())
+		{
+			logAi->error("VisitingHero is empty, expected %s", currentGarrisonHero->name);
+			return;
+		}
+
 		ai->buildArmyIn(town);
-		ai->nullkiller->unlockHero(town->visitingHero.get());
-		logAi->debug("Extracted hero %s from garrison of %s", town->visitingHero->name, town->name);
+		ai->nullkiller->unlockHero(currentGarrisonHero.get());
+		logAi->debug("Extracted hero %s from garrison of %s", currentGarrisonHero->name, town->name);
 
 		return;
 	}