microsoft-ui-xaml: Crash in swap chain during shutdown due to teardown order
Describe the bug
I have an app that uses custom controls that inherit from SwapChainPanel to render DirectX content. Each custom control is shown on a dedicated page within a NavigationView. Switching the page in the NavigationControl destroys the previously shown SwapChainPanel-based control and creates an instance of the control to be shown.
Switching between the NavigationView pages worked fine when using the Windows App SDK 1.1.5 or earlier. However, after upgrading to the Windows App SDK 1.2 I’m getting an unhandled exception when the following method of Microsoft.UI.Xaml.h is called:
template <typename D> auto consume_Microsoft_UI_Xaml_IApplicationStatics<D>::Start(winrt::Microsoft::UI::Xaml::ApplicationInitializationCallback const& callback) const
{
check_hresult(WINRT_IMPL_SHIM(winrt::Microsoft::UI::Xaml::IApplicationStatics)->Start(*(void**)(&callback)));
}
That exception simply states the following:
Unhandled exception at 0x00007FFC646AFDF2 (KernelBase.dll) in MyApp.exe: 0xC0000602: A fail fast exception occurred. Exception handlers will not be invoked and the process will be terminated immediately.
The full stack trace looks as follows:
KernelBase.dll!00007ffc646afdf2()
dcompi.dll!00007ffc07c74259()
dcompi.dll!00007ffc07c25f81()
dcompi.dll!00007ffc07bd4003()
dcompi.dll!00007ffc07c29ea6()
dcompi.dll!00007ffc07be2576()
dcompi.dll!00007ffc07be2390()
dcompi.dll!00007ffc07c3b2dd()
Microsoft.ui.xaml.dll!00007ffbff427346()
Microsoft.ui.xaml.dll!00007ffbff4273d4()
Microsoft.ui.xaml.dll!00007ffbff0bde0e()
Microsoft.ui.xaml.dll!00007ffbff109010()
Microsoft.ui.xaml.dll!00007ffbff196f6b()
Microsoft.ui.xaml.dll!00007ffbff1972bd()
Microsoft.ui.xaml.dll!00007ffbff197120()
Microsoft.ui.xaml.dll!00007ffbff180e64()
Microsoft.ui.xaml.dll!00007ffbff17ff2a()
Microsoft.ui.xaml.dll!00007ffbff401534()
Microsoft.ui.xaml.dll!00007ffbff0bde0e()
Microsoft.ui.xaml.dll!00007ffbff109010()
Microsoft.ui.xaml.dll!00007ffbff196f6b()
Microsoft.ui.xaml.dll!00007ffbff1972bd()
Microsoft.ui.xaml.dll!00007ffbff197120()
Microsoft.ui.xaml.dll!00007ffbff180e64()
Microsoft.ui.xaml.dll!00007ffbff17ff2a()
Microsoft.ui.xaml.dll!00007ffbff7ac434()
Microsoft.ui.xaml.dll!00007ffbff0bde0e()
Microsoft.ui.xaml.dll!00007ffbff0bf3d2()
Microsoft.ui.xaml.dll!00007ffbff0bec2e()
Microsoft.ui.xaml.dll!00007ffbff0beb49()
Microsoft.ui.xaml.dll!00007ffbff1f149f()
Microsoft.ui.xaml.dll!00007ffbff1f13fd()
CoreMessagingXP.dll!00007ffc211873c8()
CoreMessagingXP.dll!00007ffc211875ce()
CoreMessagingXP.dll!00007ffc2118719b()
CoreMessagingXP.dll!00007ffc21161888()
CoreMessagingXP.dll!00007ffc2116175b()
CoreMessagingXP.dll!00007ffc2113ce30()
CoreMessagingXP.dll!00007ffc21109e64()
CoreMessagingXP.dll!00007ffc2110971c()
CoreMessagingXP.dll!00007ffc210fee77()
CoreMessagingXP.dll!00007ffc21101138()
CoreMessagingXP.dll!00007ffc211015e7()
CoreMessagingXP.dll!00007ffc211014d8()
CoreMessagingXP.dll!00007ffc211475ad()
CoreMessagingXP.dll!00007ffc21147532()
CoreMessagingXP.dll!00007ffc211473e3()
user32.dll!00007ffc64f7e858()
user32.dll!00007ffc64f7e3dc()
user32.dll!00007ffc64f90c03()
ntdll.dll!00007ffc66c70ef4()
win32u.dll!00007ffc64a41104()
user32.dll!00007ffc64f91b7e()
Microsoft.ui.xaml.dll!00007ffbff1f47da()
Microsoft.ui.xaml.dll!00007ffbff1f502c()
Microsoft.ui.xaml.dll!00007ffbff1f49be()
MyApp.exe!winrt::impl::consume_Microsoft_UI_Xaml_IApplicationStatics<winrt::Microsoft::UI::Xaml::IApplicationStatics>::Start(const winrt::Microsoft::UI::Xaml::ApplicationInitializationCallback & callback) Line 157 C++
MyApp.exe!winrt::Microsoft::UI::Xaml::Application::Start::__l2::<lambda_1>::operator()(const winrt::Microsoft::UI::Xaml::IApplicationStatics & f) Line 12146 C++
MyApp.exe!winrt::impl::factory_cache_entry<winrt::Microsoft::UI::Xaml::Application,winrt::Microsoft::UI::Xaml::IApplicationStatics>::call<`winrt::Microsoft::UI::Xaml::Application::Start'::`2'::<lambda_1> &>(winrt::Microsoft::UI::Xaml::Application::Start::__l2::<lambda_1> & callback) Line 6334 C++
MyApp.exe!winrt::impl::call_factory<winrt::Microsoft::UI::Xaml::Application,winrt::Microsoft::UI::Xaml::IApplicationStatics,`winrt::Microsoft::UI::Xaml::Application::Start'::`2'::<lambda_1>>(winrt::Microsoft::UI::Xaml::Application::Start::__l2::<lambda_1> && callback) Line 6357 C++
MyApp.exe!winrt::Microsoft::UI::Xaml::Application::Start(const winrt::Microsoft::UI::Xaml::ApplicationInitializationCallback & callback) Line 12147 C++
[External Code]
The problem I have is that I’m currently clueless how that stack trace is related to my own code because none of the code in the call stack is mine. How can I figure out what the actual problem is?
As mentioned, this behavior only occurs when using Windows App SDK 1.2. What has changed there that now raises such an exception compared to the Windows App SDK 1.1.5 and earlier?
Steps to reproduce the bug
Currently only reproducible in proprietary code.
Expected behavior
If such an exception is thrown there should be a hint what the underlying issue is. It’s not obvious what is causing this.
Screenshots
No response
NuGet package version
WinUI 3 - Windows App SDK 1.2.0
Windows version
Windows 10 (21H2): Build 19044
Additional context
The following NuGet packages are used:
Microsoft.Windows.CppWinRT.2.0.220909.4 Microsoft.Windows.SDK.BuildTools.10.0.22000.196 Microsoft.WindowsAppSDK.1.1.5
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 1
- Comments: 20 (8 by maintainers)
Commits related to this issue
- Add code to react on mouse, pen and touch input events This commit adds the code that is necessary to react on mouse, pen and touch events. However, it does not actually execute code when such an eve... — committed to ackh/SwapChainPanelBugRepro by ackh 3 years ago
- Upgrade the Windows App SDK to version 1.3.230602002 This commit enables reproducing the issue described in [1]. [1]: https://github.com/microsoft/microsoft-ui-xaml/issues/7924 — committed to ackh/SwapChainPanelBugRepro by ackh 3 years ago
- Upgrade the Windows App SDK to version 1.4.231008000 Upgrading to version 1.4.231008000 of the Windows App SDK resolves the issue described in [1] which, according to the release notes, was originall... — committed to ackh/SwapChainPanelBugRepro by ackh 3 years ago
@Scottj1s I managed to create a sample with which the issue can be reproduced. This GitHub repository contains the code.
A few words regarding the content of the repository:
The code added by commit
97a6dfdc6342b351810742b34c15130c39faec67is a packaged Windows App SDK 1.1.5 app that draws on two different SwapChainPanels using DirectX. When the application is started it looks as follows:In that state, clicking the “Square View” button destroys the view showing the triangle and then creates the view that is showing a rectangle:
This is the expected behavior.
If the app is started from Visual Studio with the debugger attached, closing the app will result in an exception and the hint that there are memory leaks. That seems to be the case because the code enables the DirectX debug layer and terminating the app does not properly clean up the DirectX resources. That app behavior might need to be discussed in another thread but for the time being, it is prevented by commit
c493673c7dd750d9734bd3bcf8faf570b867bb06.Following on, commit
a2b9071724600d3b12d77b3620fdfdaaa208d501adds code that eventually causes the issue if any of the Windows App SDK 1.2 or 1.3 releases are used. Without that code, the issue is not reproducible.Finally, commit
29897029cccba330ed2417267bfd0d037cec6d96upgrades to the Windows App SDK 1.3.230602002. Starting the app in that state and switching views via “Square View” button results in the issue.Could you notify the responsible developer about this sample? I can reproduce it 100% of the time so it should be straight forward to find and fix the actual root cause.
Sure, the dump is available here.
I’m trying to put together a DirectX sample that uses the SwapChainPanel the same way as my production code. I’m currently not sure how feasible that is but it would likely help in the future in case we encounter other issues related to the SwapChainPanel.
@ackh, @anup-das the latest stacks are a bit different from the original issue reported here. But they involve the same code, so reopening this issue and alerting owners.
@ackh The problem is understood and a solution is in the works
Internal issue: task.ms/42283983
Fix will be available in Windows App SDK 1.3. Unfortunately, there is no known workaround.
@ackh Thanks - very helpful. Will pass this along to the appropriate owners.
@Scottj1s Thanks for your reply. I have symbolicated the above stack trace and it looks as shown below. In addition, the memory dump of that state is available here.