Please bear with me as I’m new to Unity. I’m using Vuforia and the Prime31 Etcetera plugin and am trying to email a screenshot of the application on an Android device. Vuforia works fine, sending an email works fine, but as soon as I try to create the screenshot LogCat shows me:
ReadPixels was called to read pixels from system frame buffer, while not inside drawing frame.
This is the code I’m using:
void SendAndroidEmail() {
int width = Screen.width;
int height = Screen.height;
Texture2D tex = new Texture2D(width, height, TextureFormat.RGB24, false);
tex.ReadPixels(new Rect(0, 0, width, height), 0, 0);
tex.Apply();
byte[] bytes = tex.EncodeToPNG();
Destroy(tex);
var path = System.IO.Path.Combine( Application.persistentDataPath, "tmp_" + System.DateTime.Now.ToString() + ".png" );
System.IO.File.WriteAllBytes( path, bytes );
EtceteraAndroid.showEmailComposer( "noone@nothing.com", "Message subject", "click <a href='http://somelink.com'>here</a> for a present", true, path );
}
I have tried experimenting with yield but to no avail as I’m not sure what I’m doing…
Thanks!