Browse Source

CGMonolith: avoid crash when all exits are blocked by friendly heroes

ArseniyShestakov 9 years ago
parent
commit
b6176649ec
1 changed files with 3 additions and 2 deletions
  1. 3 2
      lib/mapObjects/MiscObjects.cpp

+ 3 - 2
lib/mapObjects/MiscObjects.cpp

@@ -940,17 +940,18 @@ void CGMonolith::onHeroVisit( const CGHeroInstance * h ) const
 void CGMonolith::teleportDialogAnswered(const CGHeroInstance *hero, ui32 answer, TTeleportExitsList exits) const
 {
 	int3 dPos;
+	auto randomExit = getRandomExit(hero);
 	auto realExits = getAllExits(true);
 	if(!isEntrance() // Do nothing if hero visited exit only object
 		|| (!exits.size() && !realExits.size()) // Do nothing if there no exits on this channel
-		|| (!exits.size() && ObjectInstanceID() == getRandomExit(hero))) // Do nothing if all exits are blocked by friendly hero and it's not subterranean gate
+		|| ObjectInstanceID() == randomExit) // Do nothing if all exits are blocked by friendly hero and it's not subterranean gate
 	{
 		return;
 	}
 	else if(vstd::isValidIndex(exits, answer))
 		dPos = exits[answer].second;
 	else
-		dPos = CGHeroInstance::convertPosition(cb->getObj(getRandomExit(hero))->visitablePos(), true);
+		dPos = CGHeroInstance::convertPosition(cb->getObj(randomExit)->visitablePos(), true);
 
 	cb->moveHero(hero->id, dPos, true);
 }