I am trying to create the test app using unity but facing following issue:
readpixels was called to read pixels from system frame buffer, while not inside drawing frame.
Uou should wait until the end of the current frame encounters before taking the screenshot or before calling the function Texture2D.ReadPixels . This should be done with the WaitForEndOfFrame class. Please note how I cached it to avoid the creation of new Object every time the function TakeSnapshot is called.
WaitForEndOfFrame frameEnd = new WaitForEndOfFrame();
public IEnumerator TakeSnapshot(int width, int height)
yield return frameEnd;
Texture2D texture = new Texture2D(800, 800, TextureFormat.RGB24, true);
texture.ReadPixels(new Rect(0, 0, 800, 800), 0, 0);