Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

WP8 Suspend/Resume and lost rendertextures?

Discussion in 'Windows' started by bluescrn, May 19, 2014.

  1. bluescrn

    bluescrn

    Joined:
    Feb 25, 2013
    Posts:
    628
    Is there a recommended method of restoring lost rendertextures after a suspend/resume?

    This seems to be an issue on Android, too: http://forum.unity3d.com/threads/242550-Android-OnApplicationPause()-Render-Texture-issue

    Using OnApplicationPause would seem the obvious way to attempt to deal with this, but so far I'm having no success either - is there a timing issue? When after a resume does it become safe to render?

    (It'd be nice if suspend/resume could be simulated in the editor, along with discarding rendertextures in the way that it happens on Android/WP8 )
     
  2. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,491
    Doing it during OnApplicationPause is the way to go. What kind of issues are you facing when you restore them when OnApplicationPause gets called?

    P. S. You don't need to "Recreate them", as Unity does that for you. You only need to render to them again to fill their contents back.
     
  3. bluescrn

    bluescrn

    Joined:
    Feb 25, 2013
    Posts:
    628
    Hmm, after a bit more debugging+experimenting, I seem to have it working, and doesn't look like the same problem described in that Android thread.

    I'd been trying to reallocate the RenderTextures entirely - 'just in case' - with no success. I suspect that there was a material instance within NGUI (used to display the RenderTexture - a blurred grab of the game scene, behind some UI) still referencing the old/invalid RenderTexture.

    I'm no longer re-allocating them, and I'm re-rendering (with a Camera.Update) from a Monobehaviour Update(), after setting a flag in OnApplicationPause to indicate that they've been lost. Haven't tested on Android yet, but it's looking good on WP8
     
  4. chechoggomez

    chechoggomez

    Unity Technologies

    Joined:
    Feb 25, 2013
    Posts:
    91
    This is a known issue on Android, in 4.3.x when resuming, Render textures lose data, it does not happen on 4.2 though, however it has been fixed for 4.5 ( on Android). Anyway whenever you use RenderTextures (on any platform), you need to check with RenderTexture.IsCreated()

    http://docs.unity3d.com/Documentation/ScriptReference/RenderTexture.IsCreated.html

    to know if you need to render them again.

    Note that the documentation warns about this :

    http://docs.unity3d.com/Documentation/ScriptReference/RenderTexture.html

    "Keep in mind that render texture contents can become "lost" on certain events, like loading a new level, system going to a screensaver mode, in and our of fullscreen and so on. When that happens, your existing render textures will become "not yet created" again, you can check for that with IsCreated function."