RelEcs icon indicating copy to clipboard operation
RelEcs copied to clipboard

Identity "Generation" is unused

Open petergiuntoli opened this issue 2 years ago • 0 comments

Entities have a "generation" associated with them but it is always set to 1 since nothing passes a generation in to the constructor. https://github.com/Byteron/RelEcs/blob/a9051ae5750bcd883af9ae89de404f7058076e98/src/Identity.cs#L27-L32

Inside Despawn() we queue up the "unused" id without incrementing the generation https://github.com/Byteron/RelEcs/blob/a9051ae5750bcd883af9ae89de404f7058076e98/src/Archetypes.cs#L74

and then inside Spawn() we pop that id without incrementing the generation https://github.com/Byteron/RelEcs/blob/a9051ae5750bcd883af9ae89de404f7058076e98/src/Archetypes.cs#L37

Additionally, functions like IsAlive() do not check the generation at all https://github.com/Byteron/RelEcs/blob/a9051ae5750bcd883af9ae89de404f7058076e98/src/Archetypes.cs#L282-L285

It's easy to reproduce this issue since the despawned ids are used immediately

var entity = world.Spawn().Id();
world.Despawn(entity);
var anotherEntity = world.Spawn().Id();
Assert.IsFalse(entity == anotherEntity); //entity == anotherEntity will return true
Assert.IsTrue(world.IsAlive(anotherEntity));
Assert.IsFalse(world.IsAlive(entity)); // This will of course also be true unexpectedly

The same issue exists in HypEcs https://github.com/Byteron/HypEcs/issues/4

petergiuntoli avatar Oct 11 '23 16:10 petergiuntoli