fix crash on post-snapshot entity ID recycle

pull/6/head
cosmonaut 2023-11-16 10:36:11 -08:00
parent f849db955c
commit 2d333d0651
2 changed files with 5 additions and 7 deletions

View File

@ -7,11 +7,9 @@ internal class IdAssigner
uint Next; uint Next;
NativeArray<uint> AvailableIds = new NativeArray<uint>(); NativeArray<uint> AvailableIds = new NativeArray<uint>();
public uint Assign(out bool recycled) public uint Assign()
{ {
recycled = AvailableIds.TryPop(out var id); if (AvailableIds.TryPop(out var id))
if (recycled)
{ {
return id; return id;
} }

View File

@ -48,7 +48,7 @@ namespace MoonTools.ECS
return TypeToId[typeof(T)]; return TypeToId[typeof(T)];
} }
var typeId = new TypeId(TypeIdAssigner.Assign(out var _)); var typeId = new TypeId(TypeIdAssigner.Assign());
TypeToId.Add(typeof(T), typeId); TypeToId.Add(typeof(T), typeId);
ElementSizes.Add(typeId, Unsafe.SizeOf<T>()); ElementSizes.Add(typeId, Unsafe.SizeOf<T>());
@ -116,9 +116,9 @@ namespace MoonTools.ECS
public Entity CreateEntity(string tag = "") 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<TypeId>()); EntityRelationIndex.Add(entity, new IndexableSet<TypeId>());
EntityComponentIndex.Add(entity, new IndexableSet<TypeId>()); EntityComponentIndex.Add(entity, new IndexableSet<TypeId>());