Skip to main content
added 21 characters in body
Source Link

I have the following C# code in Unity version 2022.2.0a12:

[SerializeField]
public bool isLoging = true;

[SerializeField]
private RenderTexture _rt;
private NativeArray<byte> _data;

private void Start()
{
    CreateBuffer(ref _data, ref _rt);
    StartCoroutine(StartEncoding(_rt, isLoging));
}


System.Collections.IEnumerator StartEncoding(RenderTexture oRTs, bool active)
{
    while (active)
    {

        yield return new WaitForEndOfFrame();
        AsyncGPUReadback.RequestIntoNativeArray(ref _data, oRTs, 0, request =>
        {
            if (request.hasError) { 
                Debug.Log("GPU readback error detected."); 
                return;
            }
            Debug.Log("in Function ");
            // encode to png and save 
            Debug.Log("saved PNG file ");
        });


    }
}

void CreateBuffer(ref NativeArray<byte> buffer, ref RenderTexture oRTS)
{
    buffer = new NativeArray<byte>(oRTS.height * oRTS.width * 4, Allocator.Persistent, NativeArrayOptions.UninitializedMemory);
}

private void OnApplicationQuit()
{
    _data.Dispose();
}

Before even the first frame ends I get this error:

1[System.Byte] can no longer be accessed, since its owner has been invalidated.

What is happening? I can get date to be used once and then I cannot use it anymore?

My question is how can I use AsyncGPUReadback.RequestIntoNativeArray correctly so I do not lose access to my NativeArray?

I would like to hold on my data and pass it to Job so inside job i can do encoding to PNG .

I have the following C# code in Unity:

[SerializeField]
public bool isLoging = true;

[SerializeField]
private RenderTexture _rt;
private NativeArray<byte> _data;

private void Start()
{
    CreateBuffer(ref _data, ref _rt);
    StartCoroutine(StartEncoding(_rt, isLoging));
}


System.Collections.IEnumerator StartEncoding(RenderTexture oRTs, bool active)
{
    while (active)
    {

        yield return new WaitForEndOfFrame();
        AsyncGPUReadback.RequestIntoNativeArray(ref _data, oRTs, 0, request =>
        {
            if (request.hasError) { 
                Debug.Log("GPU readback error detected."); 
                return;
            }
            Debug.Log("in Function ");
            // encode to png and save 
            Debug.Log("saved PNG file ");
        });


    }
}

void CreateBuffer(ref NativeArray<byte> buffer, ref RenderTexture oRTS)
{
    buffer = new NativeArray<byte>(oRTS.height * oRTS.width * 4, Allocator.Persistent, NativeArrayOptions.UninitializedMemory);
}

private void OnApplicationQuit()
{
    _data.Dispose();
}

Before even the first frame ends I get this error:

1[System.Byte] can no longer be accessed, since its owner has been invalidated.

What is happening? I can get date to be used once and then I cannot use it anymore?

My question is how can I use AsyncGPUReadback.RequestIntoNativeArray correctly so I do not lose access to my NativeArray?

I would like to hold on my data and pass it to Job so inside job i can do encoding to PNG .

I have the following C# code in Unity version 2022.2.0a12:

[SerializeField]
public bool isLoging = true;

[SerializeField]
private RenderTexture _rt;
private NativeArray<byte> _data;

private void Start()
{
    CreateBuffer(ref _data, ref _rt);
    StartCoroutine(StartEncoding(_rt, isLoging));
}


System.Collections.IEnumerator StartEncoding(RenderTexture oRTs, bool active)
{
    while (active)
    {

        yield return new WaitForEndOfFrame();
        AsyncGPUReadback.RequestIntoNativeArray(ref _data, oRTs, 0, request =>
        {
            if (request.hasError) { 
                Debug.Log("GPU readback error detected."); 
                return;
            }
            Debug.Log("in Function ");
            // encode to png and save 
            Debug.Log("saved PNG file ");
        });


    }
}

void CreateBuffer(ref NativeArray<byte> buffer, ref RenderTexture oRTS)
{
    buffer = new NativeArray<byte>(oRTS.height * oRTS.width * 4, Allocator.Persistent, NativeArrayOptions.UninitializedMemory);
}

private void OnApplicationQuit()
{
    _data.Dispose();
}

Before even the first frame ends I get this error:

1[System.Byte] can no longer be accessed, since its owner has been invalidated.

What is happening? I can get date to be used once and then I cannot use it anymore?

My question is how can I use AsyncGPUReadback.RequestIntoNativeArray correctly so I do not lose access to my NativeArray?

I would like to hold on my data and pass it to Job so inside job i can do encoding to PNG .

Code formatting
Source Link
DMGregory
  • 140.8k
  • 23
  • 257
  • 401

I have the following C# code in Unity:

  [SerializeField]
    public bool isLoging = true;

    [SerializeField]
    private RenderTexture _rt;
    private NativeArray<byte> _data;

    private void Start()
    {
        CreateBuffer(ref _data, ref _rt);
        StartCoroutine(StartEncoding(_rt, isLoging));
    }


    System.Collections.IEnumerator StartEncoding(RenderTexture oRTs, bool active)
    {
 
        while (active)
        {

            yield return new WaitForEndOfFrame();
            AsyncGPUReadback.RequestIntoNativeArray(ref _data, oRTs, 0, request =>
            {
                if (request.hasError) { 
                Debug.Log("GPU readback error detected."); return; 
 }               return;
            }
            Debug.Log("in Function ");
                // encode to png and save 
                Debug.Log("saved PNG file ");
            });


        }
    }

    void CreateBuffer(ref NativeArray<byte> buffer, ref RenderTexture oRTS)
    {
        buffer = new NativeArray<byte>(oRTS.height * oRTS.width * 4, Allocator.Persistent, NativeArrayOptions.UninitializedMemory);
    }

    private void OnApplicationQuit()
    {
        _data.Dispose();
    }

Before even the first frame ends I get this error:

1[System.Byte] can no longer be accessed, since its owner has been invalidated.

What is happening? I can get date to be used once and then I cannot use it anymore?

My question is how can I use AsyncGPUReadback.RequestIntoNativeArray correctly so I do not lose access to my NativeArray?

I would like to hold on my data and pass it to Job so inside job i can do encoding to PNG .

I have the following C# code in Unity:

  [SerializeField]
    public bool isLoging = true;

    [SerializeField]
    private RenderTexture _rt;
    private NativeArray<byte> _data;

    private void Start()
    {
        CreateBuffer(ref _data, ref _rt);
        StartCoroutine(StartEncoding(_rt, isLoging));
    }


    System.Collections.IEnumerator StartEncoding(RenderTexture oRTs, bool active)
    {
 
        while (active)
        {

            yield return new WaitForEndOfFrame();
            AsyncGPUReadback.RequestIntoNativeArray(ref _data, oRTs, 0, request =>
            {
                if (request.hasError) { Debug.Log("GPU readback error detected."); return; }
                Debug.Log("in Function ");
                // encode to png and save 
                Debug.Log("saved PNG file ");
            });


        }
    }

    void CreateBuffer(ref NativeArray<byte> buffer, ref RenderTexture oRTS)
    {
        buffer = new NativeArray<byte>(oRTS.height * oRTS.width * 4, Allocator.Persistent, NativeArrayOptions.UninitializedMemory);
    }

    private void OnApplicationQuit()
    {
        _data.Dispose();
    }

Before even the first frame ends I get this error:

1[System.Byte] can no longer be accessed, since its owner has been invalidated.

What is happening? I can get date to be used once and then I cannot use it anymore?

My question is how can I use AsyncGPUReadback.RequestIntoNativeArray correctly so I do not lose access to my NativeArray?

I would like to hold on my data and pass it to Job so inside job i can do encoding to PNG .

I have the following C# code in Unity:

[SerializeField]
public bool isLoging = true;

[SerializeField]
private RenderTexture _rt;
private NativeArray<byte> _data;

private void Start()
{
    CreateBuffer(ref _data, ref _rt);
    StartCoroutine(StartEncoding(_rt, isLoging));
}


System.Collections.IEnumerator StartEncoding(RenderTexture oRTs, bool active)
{
    while (active)
    {

        yield return new WaitForEndOfFrame();
        AsyncGPUReadback.RequestIntoNativeArray(ref _data, oRTs, 0, request =>
        {
            if (request.hasError) { 
                Debug.Log("GPU readback error detected.");  
                return;
            }
            Debug.Log("in Function ");
            // encode to png and save 
            Debug.Log("saved PNG file ");
        });


    }
}

void CreateBuffer(ref NativeArray<byte> buffer, ref RenderTexture oRTS)
{
    buffer = new NativeArray<byte>(oRTS.height * oRTS.width * 4, Allocator.Persistent, NativeArrayOptions.UninitializedMemory);
}

private void OnApplicationQuit()
{
    _data.Dispose();
}

Before even the first frame ends I get this error:

1[System.Byte] can no longer be accessed, since its owner has been invalidated.

What is happening? I can get date to be used once and then I cannot use it anymore?

My question is how can I use AsyncGPUReadback.RequestIntoNativeArray correctly so I do not lose access to my NativeArray?

I would like to hold on my data and pass it to Job so inside job i can do encoding to PNG .

added 520 characters in body
Source Link

I have the following C# code in Unity:

  [SerializeField]
    public bool isLoging = true;

    [SerializeField]
    private RenderTexture _rt;
    private NativeArray<byte> _data;

    private void Start()
    {
        CreateBuffer(ref _data, ref _rt);
        StartCoroutine(StartEncoding(_rt, isLoging));
    } 


    System.Collections.IEnumerator StartEncoding(RenderTexture oRTs, bool active)
{    {

    
     while (active)
    {      {

    
         yield return new WaitForEndOfFrame();
        
        AsyncGPUReadback.RequestIntoNativeArray(ref _data, oRTs, 0, request =>
            {
                if (request.hasError) { Debug.Log("GPU readback error detected."); return; }
                Debug.Log("GPU readback"in errorFunction detected."); 
                return;
 // encode to png and save  
     }
            Debug.Log("in"saved FunctionPNG file ");
            //});


 encode to png and save   }
    }

    void CreateBuffer(ref NativeArray<byte> buffer, Debug.Logref RenderTexture oRTS)
    {
        buffer = new NativeArray<byte>(oRTS.height "saved* PNGoRTS.width file* "4, Allocator.Persistent, NativeArrayOptions.UninitializedMemory); 
    }

    private void OnApplicationQuit()
    {
        }_data.Dispose();
    }
}

Before even the first frame ends I get this error:

1[System.Byte] can no longer be accessed, since its owner has been invalidated.

What is happening? I can get date to be used once and then I cannot use it anymore?

My question is how can I use AsyncGPUReadback.RequestIntoNativeArray correctly so I do not lose access to my NativeArray?

I would like to hold on my data and pass it to Job so inside job i can do encoding to PNG .

I have the following C# code in Unity:

private void Start()
{
    CreateBuffer(ref _data, ref _rt);
    StartCoroutine(StartEncoding(_rt,isLoging));
}

System.Collections.IEnumerator StartEncoding(RenderTexture oRTs, bool active)
{       
     while (active)
    {          
         yield return new WaitForEndOfFrame();
        
        AsyncGPUReadback.RequestIntoNativeArray(ref _data, oRTs, 0, request =>
        {
            if (request.hasError) {
                Debug.Log("GPU readback error detected."); 
                return;
            }
            Debug.Log("in Function ");
            // encode to png and save 
            Debug.Log( "saved PNG file ");           
        });
    }
}

Before even the first frame ends I get this error:

1[System.Byte] can no longer be accessed, since its owner has been invalidated.

What is happening? I can get date to be used once and then I cannot use it anymore?

My question is how can I use AsyncGPUReadback.RequestIntoNativeArray correctly so I do not lose access to my NativeArray?

I would like to hold on my data and pass it to Job so inside job i can do encoding to PNG .

I have the following C# code in Unity:

  [SerializeField]
    public bool isLoging = true;

    [SerializeField]
    private RenderTexture _rt;
    private NativeArray<byte> _data;

    private void Start()
    {
        CreateBuffer(ref _data, ref _rt);
        StartCoroutine(StartEncoding(_rt, isLoging));
    } 


    System.Collections.IEnumerator StartEncoding(RenderTexture oRTs, bool active)
    {

        while (active)
        {

            yield return new WaitForEndOfFrame();
            AsyncGPUReadback.RequestIntoNativeArray(ref _data, oRTs, 0, request =>
            {
                if (request.hasError) { Debug.Log("GPU readback error detected."); return; }
                Debug.Log("in Function ");
                // encode to png and save  
                Debug.Log("saved PNG file ");
            });


        }
    }

    void CreateBuffer(ref NativeArray<byte> buffer, ref RenderTexture oRTS)
    {
        buffer = new NativeArray<byte>(oRTS.height * oRTS.width * 4, Allocator.Persistent, NativeArrayOptions.UninitializedMemory); 
    }

    private void OnApplicationQuit()
    {
        _data.Dispose();
    }

Before even the first frame ends I get this error:

1[System.Byte] can no longer be accessed, since its owner has been invalidated.

What is happening? I can get date to be used once and then I cannot use it anymore?

My question is how can I use AsyncGPUReadback.RequestIntoNativeArray correctly so I do not lose access to my NativeArray?

I would like to hold on my data and pass it to Job so inside job i can do encoding to PNG .

Cleanup
Source Link
DMGregory
  • 140.8k
  • 23
  • 257
  • 401
Loading
Source Link
Loading