I’m saving a Screenshot to my devices persistentDataPath. On my Mac while running the app it saves ok and will load back ok. However when running on my device it acts strangely. If I take a new screenshot it seems to save and display ok, but if I then re-load the scene the app immediately quits. Starting the app again loads fine, with the last screenshot intact.
The code’s fairly lengthy but the screen grab works fine and decodes to .png ok, then I use this to save:
var file = new File.Open(Application.persistentDataPath + "/" + "snapshot" + ".png", FileMode.Create);
var binaryWriter = new BinaryWriter(file);
binaryWriter.Write(bytes);
file.Close();
Then I read the image back with:
var directory = Application.persistentDataPath;
var fileName1 = Path.Combine( Application.persistentDataPath+"/","snapshot"+".png" );
var bytes = File.ReadAllBytes( fileName1 ); var SnapShot1 = new Texture2D( 73, 73 ); SnapShot1.LoadImage( bytes );
renderer.material.mainTexture = SnapShot1; }
I’m pretty unfamiliar with writing to devices, am I missing something obvious here which makes the app throw a fit on a same-session re load yet is fine with the screenshot file on a restart?