Unity2018.2 : Gfx.WaitForPresent() causes rendering to freeze when (Windows10) app looses focus

I just noticed a strange rendering behavior that seems new to Unity2018.2.0f2 (was previously using Unity 2017).

On a Windows PC (mine is running Windows10), when running a Unity app in windowed mode, the rendering/presenting will freeze if the app looses focus to another window and the mouse is not moved for more than 7 seconds. Scripts will still poll fine and audio works fine, too. Rendering will resume as soon as the user moves the mouse again.

This does not happen when running from inside the Unity Editor, just when running the packaged Unity app. Unfortunately, this also does not seem to happen when the Debugger is attached.

Looking at the Unity Profiler there is a stall at Gfx.WaitForPresent() until the mouse is moved again and rendering resumes.

I’ve narrowed this bug down to the use of GL.IssuePluginEvent(). The native function that it calls is doing nothing and simply return-ing.

If GL.IssuePluginEvent() is not called, the above bug does not happen; the app will render just fine.


  1. Make a Unity app that calls to a native C++ method using GL.IssuePluginEvent() at end of every frame

  2. Run packaged Windows app (the stand alone app and not in the Editor)

  3. While app is running, switch focus out of the Unity app and to another window (ex. Windows File Explorer)

  4. Don’t move mouse for about 7 seconds

  5. The Unity player window will stop rendering and will hold on the same frame until the mouse is moved again

I’m wondering if anybody else has seen this issue with the latest Unity2018.2 and (for the Unity devs) is this a known worked on problem? I did not find any open tickets in the Issue Tracker page.

Thanks in advance,

  • Chris

An Update:

it turns out that GL.IssuePluginEvent() was not the culprit. It was Texture.GetNativeTexturePtr(). Calling Texture.GetNativeTexturePtr() on every frame will cause the above bug of making the game stop rendering/presenting new frames while the window is out of focus - until the mouse gets moved.