microsoft-ui-xaml icon indicating copy to clipboard operation
microsoft-ui-xaml copied to clipboard

Closing multi-window app results in unhandled win32 exception.

Open vfabulokwe opened this issue 2 years ago • 2 comments

Describe the bug

The application will often crash, without generating any dump. Event viewer will show an “access violation error 0xc0000005”

Steps to reproduce the bug

  1. Create new MAUI app

  2. Add a button in the MainPage.xaml and implement the Clicked event handler in the code behind.

// button - to open a new window private void Btn_Clicked(object sender, EventArgs e) { var page = new ContentPage() { Content = new Label() { Text = "" } }; var win = new Window() { Page = page };

App.Current.OpenWindow(win);

}

  1. Run app targeting .net6.0-windows platform

  2. Click on the button multiple times to open multiple windows (say 10 windows)

  3. Start closing the windows and notice app crashes.

Expected behavior

All windows should close without app crashing.

Screenshots

No response

NuGet package version

No response

Windows app type

  • [ ] UWP
  • [X] Win32

Device form factor

Desktop

Windows version

Windows 11 (21H2): Build 22000

Additional context

No response

vfabulokwe avatar Sep 13 '22 18:09 vfabulokwe

Likely the same underlying issue as #7564, but happening on window close rather than opening another.

codendone avatar Sep 14 '22 04:09 codendone

@codendone Hey Mike, to add a little more context to this. We (CSS) were able to Repro this on WInUI3, but its not as consistent. On MAUI we can reproduce easily, very quickly. Please reach out if you have any questions or need us to demostrate.

hjharvey-MSFT avatar Sep 15 '22 12:09 hjharvey-MSFT

This appears to be timing issue. We are attempting to raise a layout changed event using a handler that no longer exists. This might not normally be a problem since if the handler is missing we attempt to unregister it and move on. However, this assumes that the event is attached to the source passed when the event was raised. But we explicitly don't pass a source for LayoutUpdated, so this value is null when we try to detach the event handler and we crash. This probably has something to do garbage collection since I can't ever get it to fail on the first couple of windows. Only after opening and closing a few does the crash happen.

JJBrychell avatar Oct 20 '22 20:10 JJBrychell

This issue is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 5 days.

github-actions[bot] avatar Jul 29 '23 16:07 github-actions[bot]