I am having a weird issue with texture corruption on WP8. I have a texture that I have downloaded from the web and set to an NGUI UITexture like this:
sprite.mainTexture = www.textureNonReadable;
This works great. However, when I lock my phone screen and then unlock it, all textures set in this manner are broken. Instead, they’ve taken the form of some other sprite atlas I have in memory.
When you lock the phone and unlock it, Unity has to reload all textures as D3D context gets flushed. If the texture if unavailable to be reloaded (like on the web), you will not be to display it properly. I’d suggest downloading it to temporary storage first and then loading it on the screen.
Is there no other way around this? I am loading a lot of images and saving them all to disk constantly (just in case the user locks his phone) would be extremely slow.
Once I’ve downloaded them all and saved them to disk, loading would be faster. However, the first time I load the images, I have to save them to disk, then read them into memory. This is slow. These images can change and are reloaded fairly regularly. Also, the images are often loaded into memory and then never seen again, so saving them to disk is introducing quite a bit of unnecessary storage overhead.
Well then, save the images in memory if they are changing frequently. There’s only one condition for it to work: there must be a way for unity to reach the image so it is able to reload it.
Store them in system RAM, in some byte array.
Then when the phone comes out of lock, just set back the texture data either by raw data or png data. (PNG data would use less ram).
This way you don’t have to use the hard disk and things should run fast.