From 2d333d0651edcb6f0c5cc6b23bbd078a45a0e73e Mon Sep 17 00:00:00 2001 From: cosmonaut Date: Thu, 16 Nov 2023 10:36:11 -0800 Subject: [PATCH] fix crash on post-snapshot entity ID recycle --- src/IdAssigner.cs | 6 ++---- src/World.cs | 6 +++--- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/IdAssigner.cs b/src/IdAssigner.cs index 0f11307..5cb4143 100644 --- a/src/IdAssigner.cs +++ b/src/IdAssigner.cs @@ -7,11 +7,9 @@ internal class IdAssigner uint Next; NativeArray AvailableIds = new NativeArray(); - public uint Assign(out bool recycled) + public uint Assign() { - recycled = AvailableIds.TryPop(out var id); - - if (recycled) + if (AvailableIds.TryPop(out var id)) { return id; } diff --git a/src/World.cs b/src/World.cs index c7c5d6f..f6a2ee0 100644 --- a/src/World.cs +++ b/src/World.cs @@ -48,7 +48,7 @@ namespace MoonTools.ECS return TypeToId[typeof(T)]; } - var typeId = new TypeId(TypeIdAssigner.Assign(out var _)); + var typeId = new TypeId(TypeIdAssigner.Assign()); TypeToId.Add(typeof(T), typeId); ElementSizes.Add(typeId, Unsafe.SizeOf()); @@ -116,9 +116,9 @@ namespace MoonTools.ECS public Entity CreateEntity(string tag = "") { - var entity = new Entity(EntityIdAssigner.Assign(out var recycled)); + var entity = new Entity(EntityIdAssigner.Assign()); - if (!recycled) + if (!EntityComponentIndex.ContainsKey(entity)) { EntityRelationIndex.Add(entity, new IndexableSet()); EntityComponentIndex.Add(entity, new IndexableSet());