Skip to content

Commit

Permalink
Added additional checks
Browse files Browse the repository at this point in the history
Signed-off-by: Nate Koenig <[email protected]>
  • Loading branch information
Nate Koenig committed Oct 21, 2021
1 parent 7e83e7d commit 37e5af6
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/EntityComponentManager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
20 changes: 19 additions & 1 deletion src/EntityComponentManager_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3014,11 +3014,20 @@ TEST_P(EntityComponentManagerFixture, StateMsgUpdateComponent)
auto entity = originalECMStateMap.CreateEntity();
originalECMStateMap.CreateComponent(entity, components::IntComponent(1));

int foundEntities = 0;
otherECMStateMap.Each<components::IntComponent>(
[&](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<components::IntComponent>(
[&](const Entity &, const components::IntComponent *_intComp)
{
Expand Down Expand Up @@ -3048,6 +3057,15 @@ TEST_P(EntityComponentManagerFixture, StateMsgUpdateComponent)
EntityComponentManager originalECMState;
EntityComponentManager otherECMState;

foundEntities = 0;
otherECMState.Each<components::IntComponent>(
[&](const Entity &, const components::IntComponent *)
{
foundEntities++;
return true;
});
EXPECT_EQ(0, foundEntities);

entity = originalECMState.CreateEntity();
originalECMState.CreateComponent(entity, components::IntComponent(1));

Expand Down

0 comments on commit 37e5af6

Please sign in to comment.