Reproduction (paste into fennecs.test/Entity/Entity.Ensure.cs):
[Fact]
public void Ensure_In_Stream_For()
{
using var world = new World();
world.Spawn().Add<TestStruct>();
world.Stream<TestStruct>()
.For(static (in entity, ref _) => entity.Ensure(123));
}
System.InvalidOperationException: Entity E-00000001:00001 does not have a reference type Component of type System.Int32 / [None]
System.InvalidOperationException
Entity E-00000001:00001 does not have a reference type Component of type System.Int32 / [None]
at fennecs.World.GetComponent[T](Identity identity, Match match) in /mnt/data/Projects/fennecs/fennecs/World.CRUD.cs:line 69
at fennecs.Entity.Ref[C](Match match) in /mnt/data/Projects/fennecs/fennecs/Entity.cs:line 79
at fennecs.Entity.Ensure[C](C defaultValue, Match match) in /mnt/data/Projects/fennecs/fennecs/Entity.cs:line 295
...
I'm not entirely surprised by the exception - the documentation even mentions structural changes will only be applied after For is done:
The Runner is executed directly on the calling thread. Until the runner returns, the World is in WorldMode.Deferred, meaning structural changes are applied once the Runner has finished.
Ensure should probably just throw an exception telling you to use Has/Add if the world is deferred.
Reproduction (paste into
fennecs.test/Entity/Entity.Ensure.cs):I'm not entirely surprised by the exception - the documentation even mentions structural changes will only be applied after
Foris done:Ensureshould probably just throw an exception telling you to useHas/Addif the world is deferred.