Version:
MonoGame 3.8.1
WindowsDX
Opened bug here:
opened 07:09PM - 04 Sep 23 UTC
Simple code repro:
- https://github.com/JDoucette/MonoGame-FullScreen-Exit
S… ystem:
- MonoGame 3.8.1
- Windows
- WindowsDX
Repro:
1. Game starts in windowed mode (NOTE: if the game starts in full-screen, all is well.)
2. Press "F to toggle into full screen (NOTE: if the game is toggled back to windowed mode, all is well.)
3. Press "ESC" to exit the app while in full screen
Result:
- In Release mode: Task Manager moves the app from "Apps" to "Background processes"
- In Debug mode:
THREADS:
16552 9 Worker Thread .NET System Events System.Private.CoreLib.dll!System.Threading.WaitHandle.WaitOneNoCheck
6940 4 Worker Thread .NET ThreadPool Gate System.Private.CoreLib.dll!System.Threading.WaitHandle.WaitOneNoCheck
12520 3 Worker Thread .NET ThreadPool Worker System.Private.CoreLib.dll!Interop.Kernel32.GetQueuedCompletionStatus
14468 5 Worker Thread .NET ThreadPool Worker System.Private.CoreLib.dll!Interop.Kernel32.GetQueuedCompletionStatus
14156 8 Worker Thread .NET ThreadPool Worker System.Private.CoreLib.dll!Interop.Kernel32.GetQueuedCompletionStatus
2532 0 Worker Thread <No Name>
18208 0 Worker Thread <No Name>
18512 0 Worker Thread <No Name> System.Private.CoreLib.dll!System.Threading.Thread.Join
11612 1 Main Thread Main Thread
.NET SYSTEM EVENTS THREAD, CALL STACK:
16552 9 Worker Thread .NET System Events System.Private.CoreLib.dll!System.Threading.WaitHandle.WaitOneNoCheck
System.Private.CoreLib.dll!System.Threading.WaitHandle.WaitOneNoCheck(int millisecondsTimeout) Line 139 C#
System.Private.CoreLib.dll!System.Threading.WaitHandle.WaitOne(int millisecondsTimeout) Line 111 C#
System.Private.CoreLib.dll!System.Threading.WaitHandle.WaitOne(int millisecondsTimeout, bool exitContext) Line 421 C#
System.Windows.Forms.dll!System.Windows.Forms.Control.WaitForWaitHandle(System.Threading.WaitHandle waitHandle) Line 3896 C#
System.Windows.Forms.dll!System.Windows.Forms.Control.MarshaledInvoke(System.Windows.Forms.Control caller, System.Delegate method, object[] args, bool synchronous) Line 6979 C#
System.Windows.Forms.dll!System.Windows.Forms.Control.Invoke(System.Delegate method, object[] args) Line 6426 C#
System.Windows.Forms.dll!System.Windows.Forms.WindowsFormsSynchronizationContext.Send(System.Threading.SendOrPostCallback d, object state) Line 88 C#
Microsoft.Win32.SystemEvents.dll!Microsoft.Win32.SystemEvents.SystemEventInvokeInfo.Invoke(bool checkFinalization, object[] args) Unknown
Microsoft.Win32.SystemEvents.dll!Microsoft.Win32.SystemEvents.RaiseEvent(bool checkFinalization, object key, object[] args) Unknown
Microsoft.Win32.SystemEvents.dll!Microsoft.Win32.SystemEvents.OnUserPreferenceChanging(int msg, System.IntPtr wParam, System.IntPtr lParam) Unknown
Microsoft.Win32.SystemEvents.dll!Microsoft.Win32.SystemEvents.WindowProc(System.IntPtr hWnd, int msg, System.IntPtr wParam, System.IntPtr lParam) Unknown
[Native to Managed Transition]
[Managed to Native Transition]
Microsoft.Win32.SystemEvents.dll!Microsoft.Win32.SystemEvents.WindowThreadProc() Unknown
System.Private.CoreLib.dll!System.Threading.Thread.StartCallback() Line 106 C#
Possible root cause:
- https://stackoverflow.com/questions/3832156/windows-form-application-freeze-randomly-when-run-overnight
Made a community forum post, for others to see & comment on:
- https://community.monogame.net/t/full-screen-from-windowed-hangs-on-exit/19361
I suspect others experience this issue, but since Release mode apps disappear from "Apps", they appear closed.
Until you have a Steam release, where Steam client monitors the app, and tells the gamer that they haven't closed the app yet.
Simple repro case:
If you start in Windowed mode, enter Full Screen, then Exit – the app hangs. You cannot see this in Release mode, since the application disappears as an “App” in Task Manager, and moves into “Background processes”. In Debug mode, with debugger attached, you can pause and inspect the code to see that a thread worker pool is waiting for things to be cleaned up.
Possible root cause:
c#, windows, winforms
Note that if you return to Windowed mode before exiting, all is well – you have to be in Full Screen mode for this bug to trigger.
Also, if you start the game in Full Screen and exit during Full Screen, all is well – you have to transition into Full Screen mode from Windowed mode for the bug to trigger.
It’s likely many devs experience this, but don’t notice – since the app remains only running as a background process. However, if you have a Steam release, and the Steam client monitors your app, Steam will report to the gamer that they have not closed the app – and Ctrl+Alt+Del will not show it running (unless they think to search background processes, which is a long list).