Nimesh Madhavan
Nimesh Madhavan

Reputation: 6318

How to diagnose crashes in a UWP windows store app with WinUI 2.0 tree view control

I have a UWP Windows store app with a WinUI 2.0 tree view control. I load the sub directory structure in the treeview based on user selection of a folder.

The problem I am facing is that the application crashes when I select certain folders on my dev machine. It works fine for other folders. I can see the same crash with some of my app users in the windows store diagnostic data.

Here the call stack from my machine for the crash:

Unhandled exception thrown: read access violation.
this->m_strongHost.ptr_ was nullptr.

Windows.UI.Xaml.dll!DirectUI::ModernCollectionBasePanel::CacheManager::InitCollectionsCache() Line 787
    at onecoreuap\windows\dxaml\xcp\dxaml\lib\moderncollectionbasepanel_cachemanager_partial.cpp(787)
Windows.UI.Xaml.dll!DirectUI::ModernCollectionBasePanel::CacheManager::GetItem(int indexInItemCollection, IInspectable * * ppItem) Line 868
    at onecoreuap\windows\dxaml\xcp\dxaml\lib\moderncollectionbasepanel_cachemanager_partial.cpp(868)
Windows.UI.Xaml.dll!DirectUI::ModernCollectionBasePanel::GenerateContainerAtIndexImpl(int indexInItemCollection, Windows::UI::Xaml::IUIElement * * ppReturnValue) Line 189
    at onecoreuap\windows\dxaml\xcp\dxaml\lib\moderncollectionbasepanel_iicg2_partial.cpp(189)
Windows.UI.Xaml.dll!DirectUI::ModernCollectionBasePanelGenerated::GenerateContainerAtIndex(int index, Windows::UI::Xaml::IUIElement * * ppReturnValue) Line 567
    at onecoreuap\windows\dxaml\xcp\dxaml\lib\winrtgeneratedclasses\moderncollectionbasepanel.g.cpp(567)
Windows.UI.Xaml.dll!DirectUI::ModernCollectionBasePanel::Generate(DirectUI::ModernCollectionBasePanel::CollectionIterator iterator, Windows::UI::Xaml::Controls::LayoutReference referenceInformation, unsigned char goForward) Line 1374
    at onecoreuap\windows\dxaml\xcp\dxaml\lib\moderncollectionbasepanel_partial.cpp(1374)
Windows.UI.Xaml.dll!DirectUI::ModernCollectionBasePanel::RunGenerate() Line 902
    at onecoreuap\windows\dxaml\xcp\dxaml\lib\moderncollectionbasepanel_partial.cpp(902)
Windows.UI.Xaml.dll!DirectUI::ModernCollectionBasePanel::RunVirtualization() Line 628
    at onecoreuap\windows\dxaml\xcp\dxaml\lib\moderncollectionbasepanel_partial.cpp(628)
Windows.UI.Xaml.dll!DirectUI::ModernCollectionBasePanel::MeasureOverride(Windows::Foundation::Size availableSize, Windows::Foundation::Size * pReturnValue) Line 521
    at onecoreuap\windows\dxaml\xcp\dxaml\lib\moderncollectionbasepanel_partial.cpp(521)
Windows.UI.Xaml.dll!DirectUI::FrameworkElementGenerated::MeasureOverrideProtected(Windows::Foundation::Size availableSize, Windows::Foundation::Size * pReturnValue) Line 1056
    at onecoreuap\windows\dxaml\xcp\dxaml\lib\winrtgeneratedclasses\frameworkelement.g.cpp(1056)
Windows.UI.Xaml.dll!DirectUI::FrameworkElement::MeasureOverrideFromCore(CFrameworkElement * nativeTarget, float inWidth, float inHeight, float * outWidth, float * outHeight) Line 255
    at onecoreuap\windows\dxaml\xcp\dxaml\lib\frameworkelement_partial.cpp(255)
[Inline Frame] Windows.UI.Xaml.dll!CFxCallbacks::FrameworkElement_MeasureOverride(CFrameworkElement *) Line 844
    at onecoreuap\windows\dxaml\xcp\dxaml\lib\fxcallbacks.cpp(844)
Windows.UI.Xaml.dll!CFrameworkElement::MeasureCore(XSIZEF availableSize, XSIZEF & desiredSize) Line 1597
    at onecoreuap\windows\dxaml\xcp\core\core\elements\framework.cpp(1597)
Windows.UI.Xaml.dll!CUIElement::MeasureInternal(XSIZEF availableSize) Line 4121
    at onecoreuap\windows\dxaml\xcp\core\core\elements\uielement.cpp(4121)
Windows.UI.Xaml.dll!CUIElement::Measure(XSIZEF availableSize) Line 3981
    at onecoreuap\windows\dxaml\xcp\core\core\elements\uielement.cpp(3981)
Windows.UI.Xaml.dll!CUIElement::Measure(XSIZEF availableSize) Line 4031
    at onecoreuap\windows\dxaml\xcp\core\core\elements\uielement.cpp(4031)
Windows.UI.Xaml.dll!CUIElement::Measure(XSIZEF availableSize) Line 4031
    at onecoreuap\windows\dxaml\xcp\core\core\elements\uielement.cpp(4031)
Windows.UI.Xaml.dll!CUIElement::Measure(XSIZEF availableSize) Line 4031
    at onecoreuap\windows\dxaml\xcp\core\core\elements\uielement.cpp(4031)
Windows.UI.Xaml.dll!CUIElement::Measure(XSIZEF availableSize) Line 4031
    at onecoreuap\windows\dxaml\xcp\core\core\elements\uielement.cpp(4031)
Windows.UI.Xaml.dll!CUIElement::Measure(XSIZEF availableSize) Line 4031
    at onecoreuap\windows\dxaml\xcp\core\core\elements\uielement.cpp(4031)
Windows.UI.Xaml.dll!CUIElement::Measure(XSIZEF availableSize) Line 4031
    at onecoreuap\windows\dxaml\xcp\core\core\elements\uielement.cpp(4031)
Windows.UI.Xaml.dll!CUIElement::Measure(XSIZEF availableSize) Line 4031
    at onecoreuap\windows\dxaml\xcp\core\core\elements\uielement.cpp(4031)
Windows.UI.Xaml.dll!CUIElement::Measure(XSIZEF availableSize) Line 4031
    at onecoreuap\windows\dxaml\xcp\core\core\elements\uielement.cpp(4031)
Windows.UI.Xaml.dll!CUIElement::Measure(XSIZEF availableSize) Line 4031
    at onecoreuap\windows\dxaml\xcp\core\core\elements\uielement.cpp(4031)
Windows.UI.Xaml.dll!CUIElement::Measure(XSIZEF availableSize) Line 4031
    at onecoreuap\windows\dxaml\xcp\core\core\elements\uielement.cpp(4031)
Windows.UI.Xaml.dll!CUIElement::Measure(XSIZEF availableSize) Line 4031
    at onecoreuap\windows\dxaml\xcp\core\core\elements\uielement.cpp(4031)
Windows.UI.Xaml.dll!CUIElement::Measure(XSIZEF availableSize) Line 4031
    at onecoreuap\windows\dxaml\xcp\core\core\elements\uielement.cpp(4031)
Windows.UI.Xaml.dll!CUIElement::Measure(XSIZEF availableSize) Line 4031
    at onecoreuap\windows\dxaml\xcp\core\core\elements\uielement.cpp(4031)
Windows.UI.Xaml.dll!CUIElement::Measure(XSIZEF availableSize) Line 4031
    at onecoreuap\windows\dxaml\xcp\core\core\elements\uielement.cpp(4031)
Windows.UI.Xaml.dll!CUIElement::Measure(XSIZEF availableSize) Line 4031
    at onecoreuap\windows\dxaml\xcp\core\core\elements\uielement.cpp(4031)
Windows.UI.Xaml.dll!CUIElement::Measure(XSIZEF availableSize) Line 4031
    at onecoreuap\windows\dxaml\xcp\core\core\elements\uielement.cpp(4031)
Windows.UI.Xaml.dll!CLayoutManager::UpdateLayout(unsigned int controlWidth, unsigned int controlHeight) Line 279
    at onecoreuap\windows\dxaml\xcp\core\layout\layoutmanager.cpp(279)
Windows.UI.Xaml.dll!CCoreServices::NWDrawTree(HWWalk * pHWWalk, CWindowRenderTarget * pRenderTarget, VisualTree * pVisualTree, unsigned int forceRedraw, XRECT_WH * prcDirtyRect) Line 6354
    at onecoreuap\windows\dxaml\xcp\core\dll\xcpcore.cpp(6354)
Windows.UI.Xaml.dll!CCoreServices::NWDrawMainTree(CWindowRenderTarget * pIRenderTarget, bool fForceRedraw, XRECT_WH * prcDirtyRect) Line 6078
    at onecoreuap\windows\dxaml\xcp\core\dll\xcpcore.cpp(6078)
Windows.UI.Xaml.dll!CWindowRenderTarget::Draw(CCoreServices * fForceRedraw, unsigned int prcDirtyRect, XRECT_WH *) Line 136
    at onecoreuap\windows\dxaml\xcp\core\compositor\windowrendertarget.cpp(136)
Windows.UI.Xaml.dll!CXcpBrowserHost::OnTick() Line 545
    at onecoreuap\windows\dxaml\xcp\host\win\browserdesktop\winbrowserhost.cpp(545)
Windows.UI.Xaml.dll!CXcpDispatcher::Tick() Line 1449
    at onecoreuap\windows\dxaml\xcp\win\shared\xcpwindow.cpp(1449)
Windows.UI.Xaml.dll!CXcpDispatcher::OnReentrancyProtectedWindowMessage(HWND__ * msg, unsigned int lParam, unsigned __int64) Line 1041
    at onecoreuap\windows\dxaml\xcp\win\shared\xcpwindow.cpp(1041)
[Inline Frame] Windows.UI.Xaml.dll!CXcpDispatcher::ProcessMessage(HWND__ *) Line 890
    at onecoreuap\windows\dxaml\xcp\win\shared\xcpwindow.cpp(890)
Windows.UI.Xaml.dll!CXcpDispatcher::WindowProc(HWND__ * hwnd, unsigned int msg, unsigned __int64 wParam, __int64 lParam) Line 839
    at onecoreuap\windows\dxaml\xcp\win\shared\xcpwindow.cpp(839)
Windows.UI.Xaml.dll!CDeferredInvoke::DispatchQueuedMessage(bool * dispatchedWork, bool * hasMoreWork) Line 301
    at onecoreuap\windows\dxaml\xcp\win\shared\xcpwindow.cpp(301)
[Inline Frame] Windows.UI.Xaml.dll!CXcpDispatcher::MessageTimerCallback() Line 1534
    at onecoreuap\windows\dxaml\xcp\win\shared\xcpwindow.cpp(1534)
Windows.UI.Xaml.dll!CXcpDispatcher::MessageTimerCallbackStatic(void * myUserData) Line 1526
    at onecoreuap\windows\dxaml\xcp\win\shared\xcpwindow.cpp(1526)
CoreMessaging.dll!Microsoft__CoreUI__Dispatch__TimeoutHandler$CallbackThunk(class System::Delegate *)
CoreMessaging.dll!Microsoft::CoreUI::Dispatch::TimeoutManager::Callback_OnDispatch()
CoreMessaging.dll!Microsoft::CoreUI::Dispatch::EventLoop::Callback_RunCoreLoop()
CoreMessaging.dll!Microsoft::CoreUI::Dispatch::UserAdapter::OnUserDispatch()
CoreMessaging.dll!Microsoft::CoreUI::Dispatch::UserAdapter_DoWork()
CoreMessaging.dll!Microsoft::CoreUI::Dispatch::UserAdapter_WindowProc()
user32.dll!UserCallWinProcCheckWow()
user32.dll!DispatchMessageWorker()
Windows.UI.dll!Windows::UI::Core::CDispatcher::ProcessMessage(bool bDrainQueue, bool * pbWindowMessagesProcessed, bool * pbInvokeItemProcessed) Line 320
    at onecoreuap\windows\advcore\winrt\onecoreiwindow\corewindow\common\dispatcher.cpp(320)
Windows.UI.dll!Windows::UI::Core::CDispatcher::WaitAndProcessMessagesInternal(bool bRunAlwaysOnce, void * hEventWait) Line 1950
    at onecoreuap\windows\advcore\winrt\onecoreiwindow\corewindow\common\dispatcher.cpp(1950)
Windows.UI.dll!Windows::UI::Core::CDispatcher::ProcessEvents(Windows::UI::Core::CoreProcessEventsOption options) Line 596
    at onecoreuap\windows\advcore\winrt\onecoreiwindow\corewindow\common\dispatcher.cpp(596)
Windows.UI.Xaml.dll!CJupiterWindow::RunCoreWindowMessageLoop() Line 1234
    at onecoreuap\windows\dxaml\xcp\dxaml\lib\jupiterwindow.cpp(1234)
[Inline Frame] Windows.UI.Xaml.dll!CJupiterControl::RunMessageLoop() Line 1065
    at onecoreuap\windows\dxaml\xcp\dxaml\lib\jupitercontrol.cpp(1065)
Windows.UI.Xaml.dll!DirectUI::DXamlCore::RunMessageLoop() Line 2463
    at onecoreuap\windows\dxaml\xcp\dxaml\lib\dxamlcore.cpp(2463)
twinapi.appcore.dll!Windows::ApplicationModel::Core::CoreApplicationView::Run()
twinapi.appcore.dll!<lambda>(void)()
SHCore.dll!_WrapperThreadProc()
kernel32.dll!BaseThreadInitThunk()
ntdll.dll!RtlUserThreadStart()

As you can see the entire call stack only has windows system functions, any idea on how I can proceed?

Upvotes: 1

Views: 564

Answers (1)

Nimesh Madhavan
Nimesh Madhavan

Reputation: 6318

I was able to figure out what I was doing wrong - posting it here so that it can help others.

I was allowing users to filter out items in the tree view using other controls in the form, and I had implemented it such a way that on a node, I generate the list of children of a node when the bound property was accessed.

This meant that I returned a new list of children each time the bound property was accessed, and the framework expects the list of children to be stable between immediate calls.

The solution was to cache the list of children of a node so that I only generate a new list when something actually changed.

Upvotes: 1

Related Questions