Browse Source

Fixes an issue that can cause Avalonia-based applications to crash. The GetMessage call in RunLoop() of WinUiCompositorConnection.cs has been updated to process the result of GetMessage, and terminate the message loop if a WM_QUIT message is received on the pump. (#17190)

Presently the WM_QUIT message is ignored and the loop re-enters the GetMessage call, causing an unmanaged exception and process crash.

https://github.com/AvaloniaUI/Avalonia/issues/17188
pull/17201/head
Ryan Newington 2 years ago
committed by GitHub
parent
commit
aabd038e88
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 12
      src/Windows/Avalonia.Win32/WinRT/Composition/WinUiCompositorConnection.cs

12
src/Windows/Avalonia.Win32/WinRT/Composition/WinUiCompositorConnection.cs

@ -161,12 +161,20 @@ internal class WinUiCompositorConnection : IRenderTimer, Win32.IWindowsSurfaceFa
return UnmanagedMethods.DefWindowProc(hwnd, msg, w, l); return UnmanagedMethods.DefWindowProc(hwnd, msg, w, l);
}); });
UnmanagedMethods.SetTimer(dw.Handle, IntPtr.Zero, 1000, null); UnmanagedMethods.SetTimer(dw.Handle, IntPtr.Zero, 1000, null);
while (!cts.IsCancellationRequested)
var result = 0;
while (!cts.IsCancellationRequested
&& (result = UnmanagedMethods.GetMessage(out var msg, IntPtr.Zero, 0, 0)) > 0)
{ {
UnmanagedMethods.GetMessage(out var msg, IntPtr.Zero, 0, 0);
lock (_shared.SyncRoot) lock (_shared.SyncRoot)
UnmanagedMethods.DispatchMessage(ref msg); UnmanagedMethods.DispatchMessage(ref msg);
} }
if (result < 0)
{
Logger.TryGet(LogEventLevel.Error, "WinUIComposition")
?.Log(this, "Unmanaged error in {0}. Error Code: {1}", nameof(RunLoop), Marshal.GetLastWin32Error());
}
} }
public static bool IsSupported() public static bool IsSupported()

Loading…
Cancel
Save