Search Unity

proper way to render UGUI to render texture? getting hardlock/deadlock...

Discussion in 'UGUI & TextMesh Pro' started by XRA, Oct 7, 2014.

  1. XRA

    XRA

    Joined:
    Aug 26, 2010
    Posts:
    265
    I've been using a UGUI Canvas set to Screen Space - Camera, with a camera assigned. The camera is disabled and I manually call camera.Render() with the targetTexture set to a render texture. I do this from the OnPostRender of another camera that is my main camera in the game.

    This gets me the UI in a render texture, which I then feed through some post effects. I've noticed that the longer I leave the project running- and the longer time since I last rendered the UI, the bigger the hitch when I first call Render() on that camera assigned to the UI's Canvas.

    For example, if I'm in the game mode, and switch back to the main menu, at this point I'd start telling the Camera assigned to the Canvas to render again (from within the OnPostRender of the game mode camera)

    After about 5 to 7 minutes of sitting in game mode and then switching back to the main menu, I usually end up in some type of hard lock or dead lock, it happens before the UI has blit to the screen, the editor and game is frozen.
    Trying to use attach the debugger doesn't give me any helpful information, it just seems to be sitting on one of the Thread Pools with no other information.

    I've also been able to reproduce the behavior by simply having a scene with some UGUI in it, and having the camera assigned to the Canvas disabled. The longer I wait before clicking the Enable checkbox, the larger the hitch that occurs when it gets enabled it seems. Leaving it run for about 10 minutes or longer, and then enabling the camera causes what seems like a total freeze/lock that Unity never recovers from.

    Any suggestions are appreciated!

    *edit*
    The next thing i need to try is just leaving the Canvas camera always enabled, allowing it to render into the assigned render texture on its own, and maybe just disable the Canvas itself when not needed, along with skipping the Blit if I'm not in the menu. Seems like it could sidestep the hitches / locks I'm getting... will see what happens
     
    Last edited: Oct 7, 2014
  2. XRA

    XRA

    Joined:
    Aug 26, 2010
    Posts:
    265
    I got around the issue by just leaving the UGUI camera always enabled, will enter a bug report