UnityCam icon indicating copy to clipboard operation
UnityCam copied to clipboard

After build comes out When the program loses focus and runs for a while, the program will not respond

Open haojisama opened this issue 4 years ago • 7 comments

After build comes out When the program loses focus and runs for a while, the program will not respond But the program is still running

use unity2019.3.3f1

haojisama avatar Mar 06 '20 10:03 haojisama

Can you confirm that Player Settings --> Resolution and Presentation --> "Run in Background" is checked on?

mrayy avatar Mar 07 '20 03:03 mrayy

Yes, is checked on

haojisama avatar Mar 07 '20 04:03 haojisama

Full screen seems to solve this problem. I don't know why? Is it about resolution?

haojisama avatar Mar 07 '20 04:03 haojisama

Actually, i have same problem. I use windowed mode, since im creating application which displays interactive stuff into OBS and ability to minimize it is very important for me.

Window works fine when minimized, but when you're trying to maximize it, window appears to be frozen (spinning circle, "(not responding)" in window title). You can see that your application is working, but you cannot interact with it anymore.

Some interesting details that i've found while trying to pinpoint the issue:

  • This problem was introduced in 2019.1, 2018.4 has no issues
  • Using "Exclusive Fullscreen" fixes this issue (but this is not acceptable for me)
  • Window freezes even if you send textures not every frame (once in every 10 frames, for example)
  • UnityCapture, fork by schellingb has same issue

I hope this information was useful.

3DI70R avatar Mar 13 '20 20:03 3DI70R

Same problem. Exactly 5 seconds after loses focus and wham - application crash..

but the stream in OBS continues to play fine and my game still working. It's just that the window is frozen and Windows asks me to end task. And has become completely unrecoverable.

--

I am using Unity 2019.3.2f1 and Windows 10.

It does not freeze if the window is minimized It does not freeze if the window is in focus It does not freeze if the window repeatedly focused and unfocused

maximizing window and it still freezes.

I have not tried full screen - but I fullscreen is not compatible with my game and I must use windowed.

Can you please help me find where the issue is?

guiglass avatar Mar 14 '20 10:03 guiglass

So, i think i found a solution for 2019.1+. Let me know if this works for all of you too.

This method from Win32 api removes indication that window is not responding. Although this seems like just visual fix, input and other things work fine for me when i return to the window.

Just call WindowsUtils.DisableWindowGhosting() somewhere during initialization.

public static class WindowsUtils
{
    [DllImport("user32.dll")]  
    private static extern void DisableProcessWindowsGhosting();

    public static void DisableWindowGhosting()
    {
        if (!Application.isEditor)
        {
            DisableProcessWindowsGhosting();
        }
    }
}

3DI70R avatar Mar 22 '20 09:03 3DI70R

  • Tested on Unity 2019.2.13f1 and it has no issues both in Editor and after Build.
  • Tested on Unity 2019.3.6f1, there was a problem at the build but not related to the lost focus issue, it was related to loading a shader at runtime. The lost focus issue didn't occur on my machine.

Tested on Windows 10 Version 1903.

mrayy avatar Mar 24 '20 03:03 mrayy