alecthomas / entityx

EntityX - A fast, type-safe C++ Entity-Component system
MIT License
2.21k stars 295 forks source link

Invalid entity after deleting and re-creating the same entity #197

Closed L3nn0x closed 7 years ago

L3nn0x commented 7 years ago

Hello,

I am using the compile time branch, latest commit. I have a multiplayer game where the players are represented using entities and components. Players can connect and disconnect when they want. Every time a player connects, an entity is created and some components are assigned to it. when the player disconnects, the entity is destroyed.

When a player connects, disconnects and connects again, the entity is created, destroyed and created again. When the entity is re-created, the entity has the same id, and one of the component fails the valid() assertion. It looks like the entity is considered invalid although it has been created and can be assigned components.

Do you have any idea why?

Thank you.

Edit: the error: entityx/entityx/entityx.hh:390: entityx::EntityX<StorageType, Features, Cs>::enable_if_component<C, C*> entityx::EntityX<StorageType, Features, Cs>::Entity::component(): Assertion 'valid()' failed.

L3nn0x commented 7 years ago

After investigation, it turned out it was an issue from another part of the code (the entity was deleted but still accessed afterwards).

alecthomas commented 7 years ago

👍

L3nn0x commented 7 years ago

Obviously I tried to solve this error for a week and I find the solution 10 minutes after posting the issue...

alecthomas commented 7 years ago

Always the way :) It's those rubber ducks!

L3nn0x commented 7 years ago

Indeed indeed, I definitely need one on my desk ;)