Sfoglia il codice sorgente

Fix undefined behavior in removal already removed simulated entities. (#860)

Signed-off-by: Michał Pełka <[email protected]>
Michał Pełka 5 mesi fa
parent
commit
a6561a332e

+ 7 - 0
Gems/SimulationInterfaces/Code/Source/Clients/SimulationEntitiesManager.cpp

@@ -455,6 +455,7 @@ namespace SimulationInterfaces
         if (findIt == m_simulatedEntityToEntityIdMap.end())
         if (findIt == m_simulatedEntityToEntityIdMap.end())
         {
         {
             completedCb(AZ::Failure(FailedResult(ErrorCode::RESULT_NOT_FOUND, "Entity not found")));
             completedCb(AZ::Failure(FailedResult(ErrorCode::RESULT_NOT_FOUND, "Entity not found")));
+            return;
         }
         }
 
 
         const AZ::EntityId entityId = findIt->second;
         const AZ::EntityId entityId = findIt->second;
@@ -463,6 +464,12 @@ namespace SimulationInterfaces
         AZ::Entity* entity = nullptr;
         AZ::Entity* entity = nullptr;
         AZ::ComponentApplicationBus::BroadcastResult(entity, &AZ::ComponentApplicationRequests::FindEntity, entityId);
         AZ::ComponentApplicationBus::BroadcastResult(entity, &AZ::ComponentApplicationRequests::FindEntity, entityId);
         AZ_Assert(entity, "Entity is not available.");
         AZ_Assert(entity, "Entity is not available.");
+        if (entity == nullptr)
+        {
+            AZ_Error("SimulationInterfaces", false, "Entity %s (%s) not found", name.c_str(), entityId.ToString().c_str());
+            completedCb(AZ::Failure(FailedResult(ErrorCode::RESULT_NOT_FOUND, "Entity not found")));
+            return;
+        }
         // check if entity is spawned by this component
         // check if entity is spawned by this component
         const auto ticketId = entity->GetEntitySpawnTicketId();
         const auto ticketId = entity->GetEntitySpawnTicketId();
         if (m_spawnedTickets.find(ticketId) != m_spawnedTickets.end())
         if (m_spawnedTickets.find(ticketId) != m_spawnedTickets.end())