#False positive for job write accesses (`InvalidOperationException`)

1 messages · Page 1 of 1 (latest)

raven elbow
#

Hello there,

I tried to bring our project from Entities v0.51 to v1.0 and encountered seemingly a false positive regarding the write checks. The error message is roughly the following:

InvalidOperationException: The previously scheduled job MySystem:MyTask_Job writes to the BufferTypeHandle<MyBufferElementData> MyTask_Job.JobData.myLocalVariable.myBufferField.Buffer. You must call JobHandle.Complete() on the job MySystem:MyTask_Job, before you can write to the BufferTypeHandle<MyBufferElementData> safely.

Effectively this means that current OnUpdate is supposed to call OnComplete on the Dependency created in the previous OnUpdate. This can be achieved e. g. by just calling this.Dependency.Complete() at the end of OnUpdate, however this would be potentially bad for the performance, since the other systems afterwards would be blocked from scheduling their jobs.

myLocalVariable is used using Entities.WithReadOnly(myLocalVariable) and the type is a readonly struct. It is only passed around as in parameter, only one method on it is ever called, and that reads from the myBufferField but doesn't write to it. (The data retrieved are also only read from.) So in short, there is no actual read access occuring.

As a workaround I am able to use WithNativeDisableContainerSafetyRestriction(myLocalVariable), however I don't feel comfortable to disable safety checks just because I get false positives.

I could imagine that having the buffers in a struct could trip up the system here, however since this struct is used in multiple spots and will require that data to perform certain calculations, it would be better if this would just work.

real wagon
#

Additionally - do not use Entities.ForEach. This is an API that should have been fully deprecated and removed in 1.0, but was only removed from ISystem.