This here tests that CreateEntityAt returns nullptr when trying to create an entity at an index that's already occupied. This behavior is what caused crashes before, corrupted saves had duplicate EntityIndex values that caused CreateEntityAt to return nullptr, which was then dereferenced.
| 46 | // This behavior is what caused crashes before, corrupted saves had duplicate EntityIndex values that caused CreateEntityAt to |
| 47 | // return nullptr, which was then dereferenced. |
| 48 | TEST_F(EntityImportTests, CreateEntityAtDuplicateIndexReturnsNull) |
| 49 | { |
| 50 | auto& gameState = getGameState(); |
| 51 | gameState.entities.ResetAllEntities(); |
| 52 | |
| 53 | // Create an entity at index 100 |
| 54 | auto* entity1 = gameState.entities.CreateEntityAt<Guest>(EntityId::FromUnderlying(100)); |
| 55 | ASSERT_NE(entity1, nullptr); |
| 56 | EXPECT_EQ(entity1->id.ToUnderlying(), 100u); |
| 57 | |
| 58 | // Try to create another entity at the same index, which should return nullptr |
| 59 | auto* entity2 = gameState.entities.CreateEntityAt<Guest>(EntityId::FromUnderlying(100)); |
| 60 | EXPECT_EQ(entity2, nullptr); |
| 61 | } |
| 62 | |
| 63 | // This test verifies that corrupted S6 files with duplicate EntityIndex values can be loaded without crashing. |
| 64 | TEST_F(EntityImportTests, S6ImportCorruptedDuplicateEntityIndicesDoesNotCrash) |
nothing calls this directly
no test coverage detected