Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

AsyncGPUReadback - reasons why hasError may be true?

Discussion in 'Scripting' started by DaveL99, Nov 14, 2019.

  1. DaveL99

    DaveL99

    Joined:
    Jul 5, 2018
    Posts:
    22
    I am using AsyncGPUReadback to retrieve the contents of a Compute Buffer each frame, it sometimes works, but equally sometimes the request completes with "hasError" set. I've tried most obvious things I can think of, but still struggling to diagnose the issue.

    The docs say:

    "A request that has been disposed of will result in the AsyncGPUReadbackRequest.hasError property being true."

    That's puzzled me slightly - what exactly does it mean by "disposed of"? If I have a AsyncGPUReadbackRequest object, in what way(s) could it be disposed? Can anyone elaborate more on the possible meanings of this?

    Similarly, anyone else have experience using Async readbacks, and can offer up any insight into reasons the hasError property may be set, or tips on how to debug it?

    Thanks
     
  2. palex-nx

    palex-nx

    Joined:
    Jul 23, 2018
    Posts:
    1,745
    Doc states also what

    > The result is accessible only for a single frame once is successfully fulfilled and this request is then disposed of in the following frame.


    Looks like you can't dispose it. It is disposed automatically by unity engine and after that you can't use it anymore. I think you can't save that reference outside of callback. Copy required data from it and leave it to die in the wild
     
    DaveL99 likes this.
  3. DaveL99

    DaveL99

    Joined:
    Jul 5, 2018
    Posts:
    22
    A thousand thankyous! That gave me exactly the clue I needed to figure out my mistake, not sure how I glossed over that bit of the Doc.

    I'm issuing a new request every frame, and keeping a Queue of them, and also each frame checking if the first request in the queue is "done" and if so grabbing the data. ... But of course, it's possible that more than one request could have completed in the same frame! So if I check the rest of the Queue for "done" requests, rather than just the first one only, then my "hasError" problems disappear!

    Thanks again.
     
    palex-nx likes this.