Hey.
I have a job that tries to count valid pixels in a texture and save it into a NativeArray with a single variable inside it. Every time I run the job I get a different result even though the inputs are the same. Here’s an example simplified version of my job:
struct ExampleJob : IJobParallelFor
{
[NativeDisableParallelForRestriction] public NativeArray<ulong> validPixels;
public void Execute(int index)
{
if(some condition is true)
validPixels[0] = validPixels[0] + 1;
}
}
Even if the condition is always true, the result will be different every time. I assume this is caused by a race condition since I constantly try to read and write into validPixels[0].
It’s impossible to use a lock or any other methods that depend on references. Is there any solution to this problem? Thanks