-
@friflo edit: format C# code Is the "CommandBuffer" not thread-safe? I am spawning around 1000 elements, and beyond a certain point, I receive this error message:
protected override void OnUpdate()
{
CommandBuffer cmdBuffer = Query.Store.GetCommandBuffer();
var elementJob = Query.ForEach((transients, entities) =>
{
var counter = 0;
foreach (ref var transient in transients.Span)
{
transient.LifeTime -= Tick.deltaTime;
if (transient.LifeTime <= 0) {
cmdBuffer.DeleteEntity(entities[counter]);
} else {
transient.Position += transient.Velocity * Tick.deltaTime;
}
counter++;
}
});
elementJob.JobRunner = runner;
elementJob.RunParallel();
cmdBuffer.Playback();
} |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
Hi @KloBiX, thanks for reporting this. In my first answer I wrote: After diving into this I took a different decision. It is a valid use case to use a Instead I added So please use the new var cmdBuffer = Query.Store.GetCommandBuffer().Synced; I also fixed a bug that was specific to the last parameter in Recommendation Just published the fixed package to nuget. Version: v2.0.0-preview.7 Note: I reproduced your exception with: |
Beta Was this translation helpful? Give feedback.
-
hey @MaansenV, I guess your code was used as template for the bug above. So I added this comment to let you know. |
Beta Was this translation helpful? Give feedback.
Hi @KloBiX,
thanks for reporting this.
In my first answer I wrote:
"The intention is:
CommandBuffer
must be thread-safe"After diving into this I took a different decision.
So - as before -
CommandBuffer
is NOT thread safe. I fixed the documentation.It is a valid use case to use a
CommandBuffer
in single threaded queries.In this case the cost for a redundant
lock
is too high. ~50 ns per lock.Instead I added
CommandBuffer.Synced
. This property must be used in parallel (multi threaded) queries.Its interface is same as
CommandBuffer
.So please use the new
Synced
property. E.g.I also fixed a bug that was specific to the last paramete…