Closed dkominek closed 1 year ago
Reading through the latest on Gitter, it seems that maybe useBuffer would resolve the issue? LMK your thoughts.
hello, sorry for not answering earlier but that's probably it yeah. by default systems iterate entities directly on the underlying set to reduce memory copy. When you dispose it it is swapped with the last entity of the set at the same time. useBuffer
parameter of the system constructor is specifically here for that case, so that the system iterate on a copy of the set instead of the set directly.
When I call Dispose within an override of Update(TState state, in Entity entity) on an AEntitySetSystem, the next entity in the ReadOnlySpan of Update(TSatate state, in Entity entity) is being disposed instead of the current entity. I narrowed the issue down to the EntityDisposingMessage updating the Entity Id to the next entity before the EntityDisposedMessage is published, causing the wrong entity to be disposed. This only occurs if they system has more than 1 entity being acted upon and any entity except the last entity is disposed.
Here is an example system: