Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Identity "Generation" is unused #39

Open
petergiuntoli opened this issue Oct 11, 2023 · 0 comments
Open

Identity "Generation" is unused #39

petergiuntoli opened this issue Oct 11, 2023 · 0 comments

Comments

@petergiuntoli
Copy link

petergiuntoli commented Oct 11, 2023

Entities have a "generation" associated with them but it is always set to 1 since nothing passes a generation in to the constructor.

RelEcs/src/Identity.cs

Lines 27 to 32 in a9051ae

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public Identity(int id, ushort generation = 1)
{
Id = id;
Generation = generation;
}

Inside Despawn() we queue up the "unused" id without incrementing the generation

UnusedIds.Enqueue(identity);

and then inside Spawn() we pop that id without incrementing the generation

var identity = UnusedIds.Count > 0 ? UnusedIds.Dequeue() : new Identity(++EntityCount);

Additionally, functions like IsAlive() do not check the generation at all

RelEcs/src/Archetypes.cs

Lines 282 to 285 in a9051ae

internal bool IsAlive(Identity identity)
{
return Meta[identity.Id].Identity != Identity.None;
}

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 Byteron/HypEcs#4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant