Skip to content

Commit 5239466

Browse files
committed
+ check if entity still exists on deferred
+ minor on entitymapper
1 parent e02cb81 commit 5239466

File tree

2 files changed

+14
-13
lines changed

2 files changed

+14
-13
lines changed

src/EntityMapper.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,8 @@ private bool RemoveParent(EcsID parentId)
104104
return true;
105105
}
106106

107-
private static void OnEntityRemoved(World world, EcsID id)
108-
=> world.RelationshipEntityMapper.Remove(id);
107+
private void OnEntityRemoved(World world, EcsID id)
108+
=> Remove(id);
109109

110110
private void ApplyPolicy(EcsID id)
111111
{

src/World.Deferred.cs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ namespace TinyEcs;
55
public sealed partial class World
66
{
77
private readonly ConcurrentQueue<DeferredOp> _operations = new();
8-
private WorldState _worldState = new () { Locks = 0 };
8+
private WorldState _worldState = new() { Locks = 0 };
99

1010
public bool IsDeferred => _worldState.Locks > 0;
1111
public bool IsMerging => _worldState.Locks < 0;
@@ -136,23 +136,24 @@ private void Merge()
136136
switch (op.Op)
137137
{
138138
case DeferredOpTypes.DestroyEntity:
139-
Delete(op.Entity);
139+
if (Exists(op.Entity))
140+
Delete(op.Entity);
140141
break;
141142

142143
case DeferredOpTypes.SetComponent:
143-
{
144-
(var array, var row) = Attach(op.Entity, op.ComponentInfo.ID, op.ComponentInfo.Size);
145-
array?.SetValue(op.Data, row & TinyEcs.Archetype.CHUNK_THRESHOLD);
144+
{
145+
(var array, var row) = Attach(op.Entity, op.ComponentInfo.ID, op.ComponentInfo.Size);
146+
array?.SetValue(op.Data, row & TinyEcs.Archetype.CHUNK_THRESHOLD);
146147

147-
break;
148-
}
148+
break;
149+
}
149150

150151
case DeferredOpTypes.UnsetComponent:
151-
{
152-
Detach(op.Entity, op.ComponentInfo.ID);
152+
{
153+
Detach(op.Entity, op.ComponentInfo.ID);
153154

154-
break;
155-
}
155+
break;
156+
}
156157
}
157158
}
158159

0 commit comments

Comments
 (0)