schellingb / UnityCapture

Streams Unity rendered output to other Windows applications as virtual capture device
430 stars 68 forks source link

If application loses focus - 5 seconds later it crashes. #9

Open guiglass opened 4 years ago

guiglass commented 4 years ago

I am using Unity 2019.3.2f1 and Windows 10. when I build and run a windowed game and I then click outside of the window and un-focus the game, after 5 seconds it freezes and crashes.

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.

Exact same issue as this fork

Is there anything I can try? It does not happen in the editor, only windowed final builds. And I believe it only affects Unity 2019 and up.

--

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?

--

I did not see a crash report I think because Unity never actually crashed and the game was still playing every while the window was locked up. So I have nothing much to post from the error logs. However there was one line at the very end of Player.log:

utp:{"type":"MemoryLeaks","version":2,"phase":"Immediate","time":1584182609881,"processId":35128,"allocatedMemory":155286,"memoryLabels":[{"Permanent":40},{"NewDelete":432},{"Thread":64},{"Manager":2928},{"VertexData":1632},{"GfxDevice":8384},{"Animation":99552},{"Physics":32},{"Serialization":40},{"File":5864},{"String":739},{"DynamicArray":9616},{"PoolAlloc":56},{"Sprites":8280},{"GI":344},{"WebRequest":2978},{"VR":4176},{"Secure":10785},{"Subsystems":-656}]}

--

Also something very interesting I found was that when i enabled "Use DXGI Flip Model Swapchain for D3D11" checkbox in player settings I then noticed the game window would become unresponsive however I still could see my game playing in the game window like normal (it was all grayed out and a rotating throbber instead of mouse pointer) but the game was still playing.

When I set that checkbox disabled then whenever the window freezes I see the game display is stuck and not changing.

Not that this has much to do with why it's crashing, but it was the only thing I found that had any effect.

guiglass commented 4 years ago

Some more interesting findings, if the application window is frozen, but the camera is destroyed after a timer, then the window comes back into focus and everything is working - still not a solution because the camera is well, destroyed...

hahaCrazy commented 4 years ago

我也碰到了同样的问题,我用Unity搭建的一个3D场景,在unity主相机上挂上UnityCapture.cs脚本,然后打包并运行,然后再开启其它视频会议软件,没过一会,发现Unity打包处来的客户端已经显示无响应,请问有什么好的解决方法吗

SilenSang commented 3 years ago

I encountered the same problem too. It seems to be related to the window losing focus.