Skip to content

Commit

Permalink
Fixes an issue that can cause Avalonia-based applications to crash. T…
Browse files Browse the repository at this point in the history
…he 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.

#17188
  • Loading branch information
ryannewington authored Oct 4, 2024
1 parent 492cbe5 commit aabd038
Showing 1 changed file with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -161,12 +161,20 @@ private void RunLoop()
return UnmanagedMethods.DefWindowProc(hwnd, msg, w, l);
});
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)
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()
Expand Down

0 comments on commit aabd038

Please sign in to comment.