I don’t get it. I thought I can use IsCompleted
to check if the job is finished and then process the result (the job takes quite a while), but right after starting my testapplication it tries to execute float aPlusB = result[0];
which is in the IsCompleted
condition and of course throws
void Update()
{
if (Input.GetKeyDown("g"))
{
result = new NativeArray<float>(1, Allocator.Persistent);
jobData = new ExpensiveJob();
jobData.a = 10;
jobData.b = -9;
jobData.result = result;
handle = jobData.Schedule();
started = true;
}
if (handle.IsCompleted && started)
{
handle.Complete();
float aPlusB = result[0];
Debug.Log("Result" + result[0]);
result.Dispose();
started = false;
}
}
NullReferenceException: Object reference not set to an instance of an object
Unity.Collections.NativeArray`1[T].CheckElementReadAccess
So I implemented the started
bool
as a workaround, but is this working as intended ? Why is the JobHandle.IsCompleted
true
on default?
Thanks in advance