Skip to content

Commit

Permalink
Fix EntitySortedSet.Remove while fully used
Browse files Browse the repository at this point in the history
  • Loading branch information
Helco authored and Doraku committed Feb 20, 2022
1 parent 6877765 commit aa97a00
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
13 changes: 13 additions & 0 deletions source/DefaultEcs.Test/EntitySortedSetTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,19 @@ public void EntityRemoved_Should_be_called()
Check.That(entity).IsEqualTo(removedEntity);
}

[Fact]
public void Remove_While_Full_Should_Not_Crash()
{
using World world = new();

for (int i = 0; i < 8; i++) // choose count such that _entities is completly used
world.CreateEntity().Set(i);

using EntitySortedSet<int> set = world.GetEntities().AsSortedSet<int>();

set.GetEntities()[0].Remove<int>();
}

#endregion
}
}
2 changes: 1 addition & 1 deletion source/DefaultEcs/EntitySortedSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ void Internal.IEntityContainer.Remove(int entityId)
ref int index = ref _mapping[entityId];
if (index != -1)
{
int length = Count-- - index;
int length = --Count - index;

if (length > 0)
{
Expand Down

0 comments on commit aa97a00

Please sign in to comment.