The order of operations for one or more entities despawning from an archetype where one or more of the Relations target that Entity itself causes an unhandled exception.
Repro:
Crashes on all runs.
[Theory]
[InlineData(1)]
[InlineData(2)]
[InlineData(3)]
[InlineData(10)]
[InlineData(69)]
[InlineData(200)]
public void DespawningBulkInSelfReferencedArchetypeIsPossible(int relations)
{
using var world = new World();
var subjects = new List<Entity>();
var rnd = new Random(1234 + relations);
for (var i = 0; i < relations; i++)
{
subjects.Add(world.Spawn());
}
// Create a bunch of self-referential relations
foreach (var subject in subjects)
{
subject.Add(rnd.Next(), subject);
}
var query = world.Query<int>(Match.Entity).Compile();
Assert.Equal(relations, query.Count);
query.Truncate(relations/2);
Assert.Equal(relations/2, query.Count);
}
Crashes on Runs greater than 1:
[Theory]
[InlineData(1)]
[InlineData(2)]
[InlineData(3)]
[InlineData(10)]
[InlineData(69)]
[InlineData(200)]
public void DespawningSingleInSelfReferencedArchetypeIsPossible(int relations)
{
using var world = new World();
var subjects = new List<Entity>();
var rnd = new Random(1234 + relations);
for (var i = 0; i < relations; i++)
{
subjects.Add(world.Spawn());
}
// Create a bunch of self-referential relations
foreach (var subject in subjects)
{
subject.Add(rnd.Next(), subject);
}
var query = world.Query<int>(Match.Entity).Compile();
Assert.Equal(relations, query.Count);
// Create a bunch of self-referential relations
foreach (var subject in subjects)
{
subject.Despawn();
}
Assert.Equal(relations/2, query.Count);
}
Potential Fix:
Difficult to fix heuristically, but:
(easy-ish) change order of operations so Archetype is migrated as soon as entity is removed
(difficult) bulk despawns need to carry additional metadata (or resolve that) as they happen
will always requires some sort of linear search to collect and match relations :(
What:
The order of operations for one or more entities despawning from an archetype where one or more of the Relations target that Entity itself causes an unhandled exception.
Repro:
Crashes on all runs.
Crashes on Runs greater than 1:
Potential Fix:
Difficult to fix heuristically, but: