Hey @richardkettlewell , looks like it’s case number is 1388364.
Same problem here Is there some public link for this issue now? I would like to track it’s progress too.
QA haven’t processed it yet. I’m not sure of the criteria, but the report hasn’t got the top rating (maybe some repro steps are missing, or repro project, etc) so that affects its priority for processing. If it’s not too much trouble, submitting your own bug will ensure you get email updates on its progress. And it may get processed sooner if its a higher quality report.
I am getting the same error, have you found a solution to that?
Thanks.
Any updates here?
I am also having that issue when reusing (once every x seconds) a NativeArray that I initialized with Allocator.Persistent.
In addition i will get a “AsyncGPUReadback - NativeArray does not have read/write access” as error log.
Still the code runs.
QA are struggling to reproduce the submitted bug (1388364) because it doesn’t include a reproduction project. QA have asked the author if they can provide a repro project. Alternatively, anyone else who can submit a better bug report will speed up getting it fixed!
2022.1 Still on going issue, there is an open ticket
https://issuetracker.unity3d.com/is…ndisposable-when-using-requestintonativearray
However, if you use WaitForCompletion(), it stops showing this error but fps drops of course.
I read this all as next issue :
AsyncGPUReadback.RequestIntoNativeArray takes ownership of Native array until request is done , so
reason for error is due the fact that ownership is given to the AsyncGPUReadback.RequestIntoNativeArray function , I think that we need to make sure that reading to a buffer is done before we make another request for reading and at that moment ownership is back etc …
so much trouble for a basic array copy…
and still unresolved after 2 years… zzzZzz
I tried another approach: create a nativearray each AsyncGPUReadback.RequestIntoNativeArray call but when i can’t deallocate this data, i got this error:
InvalidOperationException: The Unity.Collections.NativeArray`1[System.Byte] has been set to undisposable and cannot be deallocated.
Debug.Log("create request");
NativeArray<byte> buffer = new NativeArray<byte>(w * h * 16, Allocator.Persistent, NativeArrayOptions.UninitializedMemory);
AsyncGPUReadbackRequest request = AsyncGPUReadback.RequestIntoNativeArray(ref buffer, rt);
float acc = 0;
while (!request.done && acc < 1f)
{
acc += Time.deltaTime;
yield return null;
}
OnReadbackComplete(request);
buffer.Dispose();
Debug.Log("release request");
Any help is very welcome.
Thank you so much, I made it work with something like this
private Queue<NativeArray<byte>> buffers;
This issue is still happening on 2022.2.1f1.
NativeArray<float> floatArray = new NativeArray<float>(floatBuffer.count, Allocator.Persistent);
NativeArray<States> statesArray = new NativeArray<States>(statesBuffer.count, Allocator.Persistent);
// Requests from GPU to CPU
AsyncGPUReadbackRequest[] requests = new AsyncGPUReadbackRequest[]
{
AsyncGPUReadback.RequestIntoNativeArray(ref floatArray, floatBuffer),
AsyncGPUReadback.RequestIntoNativeArray(ref statesArray, statesBuffer),
};
while (!requests.All(x => x.done))
{
yield return null;
}
// Processes GPU data
if (!requests.Any(x => x.hasError))
{
// Try and access any of the created native arrays. Errors out
}
This code also leads to “InvalidOperationException: NativeArray can no longer be accessed, since its owner has been invalidated.”
Definitely doesn’t seem to be the case from the example above, so https://issuetracker.unity3d.com/issues/asyncgpureadback-dot-requestintonativearray-causes-invalidoperationexception-on-nativearray isn’t properly fixed unless I’m misunderstanding something.
Suffering from it as well, in 2022.2.10.
OK, I solved it for now, but not sure if this will suit everybody.
I am using the readback for objectpicking (using colors as ID). It seems you cannot execute the readbacks in an (Late)Update and wait for the request to finish. The request might happen before the other is finished. Indeed, similar someone else mentioned a bit earlier.
I just solved it using a boolean check, setting it to false if the event is triggered - and then a new request is allowed to be made (setting the bool to true). In my case I do not want to deal with queues, it is not needed anyway.
Bump.
Still a problem in 2022.2.8f1. It only happens when a request into a native array is made before a previous request has been resolved, as mentioned above. Is this a bug or is it not supported to queue multiple requests like this?
I recommend submitting a bug report for this. We should either support it, or provide good error feedback if we can’t. Anything else is a bug imo.
Hi, thank you for replying.
I have submitted a bug report 36698, though my case seems to be a bit more specific than I originally thought.
Basically AsyncGPUReadback.RequestIntoNativeArray causes an InvalidOperationException when requesting data into a NativeArray created with NativeArray.GetSubArray.
AsyncGPUReadback.Request works normally, but then you have to do an extra array copy, so while it works it would be nice to get this fixed.
Thanks
Turns out its a bug.
And now we need to wait around 6 months to get a fix into latest stable version of Unity. Which is better than nothing, thanks for reporting!
I’m still getting this error in 2021.3.15f1. Is it possible that this failed to be ported from 2021.2 to 2021.3?