diff --git a/src/EntityComponentManager.cc b/src/EntityComponentManager.cc index 62a82e75a0..1b261294d0 100644 --- a/src/EntityComponentManager.cc +++ b/src/EntityComponentManager.cc @@ -1667,6 +1667,12 @@ void EntityComponentManager::SetState( if (nullptr == comp) { auto newComp = components::Factory::Instance()->New(type); + if (nullptr == newComp) + { + ignerr << "Failed to create component type [" + << compMsg.type() << "]" << std::endl; + continue; + } std::istringstream istr(compMsg.component()); newComp->Deserialize(istr); this->CreateComponentImplementation(entity, type, newComp.get()); diff --git a/src/EntityComponentManager_TEST.cc b/src/EntityComponentManager_TEST.cc index c32ef6f778..ed45452d66 100644 --- a/src/EntityComponentManager_TEST.cc +++ b/src/EntityComponentManager_TEST.cc @@ -3014,11 +3014,20 @@ TEST_P(EntityComponentManagerFixture, StateMsgUpdateComponent) auto entity = originalECMStateMap.CreateEntity(); originalECMStateMap.CreateComponent(entity, components::IntComponent(1)); + int foundEntities = 0; + otherECMStateMap.Each( + [&](const Entity &, const components::IntComponent *) + { + foundEntities++; + return true; + }); + EXPECT_EQ(0, foundEntities); + // update the other ECM to have the new entity and component msgs::SerializedStateMap stateMapMsg; originalECMStateMap.State(stateMapMsg); otherECMStateMap.SetState(stateMapMsg); - int foundEntities = 0; + foundEntities = 0; otherECMStateMap.Each( [&](const Entity &, const components::IntComponent *_intComp) { @@ -3048,6 +3057,15 @@ TEST_P(EntityComponentManagerFixture, StateMsgUpdateComponent) EntityComponentManager originalECMState; EntityComponentManager otherECMState; + foundEntities = 0; + otherECMState.Each( + [&](const Entity &, const components::IntComponent *) + { + foundEntities++; + return true; + }); + EXPECT_EQ(0, foundEntities); + entity = originalECMState.CreateEntity(); originalECMState.CreateComponent(entity, components::IntComponent(1));