Sfoglia il codice sorgente

Fix crash on losing mission-critical hero in battle

Ivan Savenko 1 anno fa
parent
commit
ee7bd87b8d
1 ha cambiato i file con 7 aggiunte e 3 eliminazioni
  1. 7 3
      lib/gameState/CGameState.cpp

+ 7 - 3
lib/gameState/CGameState.cpp

@@ -1444,18 +1444,22 @@ bool CGameState::checkForVictory(const PlayerColor & player, const EventConditio
 		{
 			// list of players that need to control object to fulfull condition
 			// NOTE: cgameinfocallback specified explicitly in order to get const version
-			const auto & team = CGameInfoCallback::getPlayerTeam(player)->players;
+			const auto * team = CGameInfoCallback::getPlayerTeam(player);
 
 			if (condition.objectID != ObjectInstanceID::NONE) // mode A - flag one specific object, like town
 			{
-				return team.count(getObjInstance(condition.objectID)->tempOwner) != 0;
+				const auto * object = getObjInstance(condition.objectID);
+
+				if (!object)
+					return false;
+				return team->players.count(object->getOwner()) != 0;
 			}
 			else
 			{
 				for(const auto & elem : map->objects) // mode B - flag all objects of this type
 				{
 					 //check not flagged objs
-					if ( elem && elem->ID == condition.objectType.as<MapObjectID>() && team.count(elem->tempOwner) == 0 )
+					if ( elem && elem->ID == condition.objectType.as<MapObjectID>() && team->players.count(elem->getOwner()) == 0 )
 						return false;
 				}
 				return true;