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 #4

Open
petergiuntoli opened this issue Oct 11, 2023 · 1 comment
Open

Identity "Generation" is unused #4

petergiuntoli opened this issue Oct 11, 2023 · 1 comment

Comments

@petergiuntoli
Copy link

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

HypEcs/src/Identity.cs

Lines 27 to 32 in 2cc54cd

[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

HypEcs/src/Archetypes.cs

Lines 283 to 287 in 2cc54cd

[MethodImpl(MethodImplOptions.AggressiveInlining)]
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 RelEcs Byteron/RelEcs#39

@Gnivom
Copy link

Gnivom commented Oct 12, 2023

PR #5 fixes the issue:

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

2 participants