CommunityToolkit / WindowsCommunityToolkit

The Windows Community Toolkit is a collection of helpers, extensions, and custom controls. It simplifies and demonstrates common developer tasks building .NET apps with UWP and the Windows App SDK / WinUI 3 for Windows 10 and Windows 11. The toolkit is part of the .NET Foundation.
https://docs.microsoft.com/windows/communitytoolkit/
Other
5.89k stars 1.38k forks source link

Exception thrown when clicking Datagrid header for sorting (repeatedly changing ItemsSource) #4080

Open omnilogix opened 3 years ago

omnilogix commented 3 years ago

Describe the bug

When attempting to sort the datagrid as described here: https://docs.microsoft.com/en-us/windows/communitytoolkit/controls/datagrid_guidance/group_sort_filter, the app crashes. The number clicks required to crash the app varies from a few to a few dozen.

Steps to Reproduce

Steps to reproduce the behavior: Reunion_Demo3.zip

  1. Build and run the attached sample app
  2. Click on the datagrid "name" column header multiple times (1 to 50)
  3. Watch for the crash image

Microsoft.ui.xaml.dll!ctl::AutoPeg<struct IInspectable,0>::~AutoPeg<struct IInspectable,0>(void) Microsoft.ui.xaml.dll!DirectUI::UIElement::ResetAutomationPeer() Microsoft.ui.xaml.dll!DirectUI::UIElement::~UIElement(void) Microsoft.ui.xaml.dll!ctl::ComObject::vector deleting destructor'(unsigned int) Microsoft.ui.xaml.dll!ctl::ComBase::ReleaseImpl() Microsoft.ui.xaml.dll!DirectUI::UIAffinityReleaseQueue::DoCleanup() Microsoft.ui.xaml.dll!DirectUI::UIAffinityReleaseQueue::BuildTree() Microsoft.ui.xaml.dll!DirectUI::BuildTreeService::BuildTrees() Microsoft.ui.xaml.dll!AgCoreCallbacks::FrameworkCallbacks_PhasedWorkDistributor_PerformWork() Microsoft.ui.xaml.dll!CCoreServices::NWDrawTree() Microsoft.ui.xaml.dll!CCoreServices::NWDrawMainTree() Microsoft.ui.xaml.dll!CWindowRenderTarget::Draw() Microsoft.ui.xaml.dll!CXcpBrowserHost::OnTick() Microsoft.ui.xaml.dll!CXcpDispatcher::Tick() Microsoft.ui.xaml.dll!CXcpDispatcher::OnReentrancyProtectedWindowMessage() Microsoft.ui.xaml.dll!CXcpDispatcher::WindowProc() Microsoft.ui.xaml.dll!CDeferredInvoke::DispatchQueuedMessage() Microsoft.ui.xaml.dll!Microsoft::WRL::Details::DelegateArgTraits<long (__cdecl ABI::Windows::Foundation::ITypedEventHandler_impl<ABI::Windows::Foundation::Internal::AggregateType<ABI::Microsoft::System::DispatcherQueueTimer *,ABI::Microsoft::System::IDispatcherQueueTimer *>,IInspectable *>::*)(ABI::Microsoft::System::IDispatcherQueueTimer *,IInspectable *)>::DelegateInvokeHelper<Microsoft::WRL::Implements<Microsoft::WRL::RuntimeClassFlags<2>,ABI::Windows::Foundation::ITypedEventHandler<ABI::Microsoft::System::DispatcherQueueTimer *,IInspectable *>,Microsoft::WRL::FtmBase>,<lambda_fbe4f38be23425399af0724cc79ee2d3> &,1,ABI::Microsoft::System::IDispatcherQueueTimer *,IInspectable *>::Invoke() CoreMessagingXP.dll!Microsoft::WRL::Details::DelegateArgTraits<long ( Windows::Foundation::ITypedEventHandler_impl<struct Windows::Foundation::Internal::AggregateType<class Microsoft::System::DispatcherQueueTimer *,struct Microsoft::System::IDispatcherQueueTimer *>,struct IInspectable *>::*)(struct Microsoft::System::IDispatcherQueueTimer *,struct IInspectable *)>::DelegateInvokeHelper<struct Microsoft::WRL::Implements<struct Microsoft::WRL::RuntimeClassFlags<2>,struct Windows::Foundation::ITypedEventHandler<class Microsoft::System::DispatcherQueueTimer *,struct IInspectable *>,class Microsoft::WRL::FtmBase>,class <lambda_67362a0a5709a7b3d634a36a54ed7d36>,-1,struct Microsoft::System::IDispatcherQueueTimer *,struct IInspectable *>::Invoke(struct Microsoft::System::IDispatcherQueueTimer *,struct IInspectable *) CoreMessagingXP.dll!Microsoft::WRL::InvokeTraits<-2>::InvokeDelegates<class <lambda_00d64a5d69eb8cd85a8562b0747f7e4a>,struct Windows::Foundation::ITypedEventHandler<class Microsoft::System::DispatcherQueueTimer *,struct IInspectable *> >(class <lambda_00d64a5d69eb8cd85a8562b0747f7e4a>,class Microsoft::WRL::Details::EventTargetArray *,class Microsoft::WRL::EventSource<struct Windows::Foundation::ITypedEventHandler<class Microsoft::System::DispatcherQueueTimer *,struct IInspectable *>,struct Microsoft::WRL::InvokeModeOptions<-2> > *) CoreMessagingXP.dll!Microsoft::System::DispatcherQueueTimer::TimerCallback(void *) CoreMessagingXP.dll!CFlat::SehSafe::Execute<<lambda_654db17c35df07198786f0867aa10de6>>() CoreMessagingXP.dll!Microsoft::CoreUI::Dispatch::TimeoutHandler::ImportAdapter$(class CFlat::Box$1<struct CFlat::FunctionPointerAndUserData$1<long (*)(void *)> > *) CoreMessagingXP.dll!Microsoft::CoreUI::Dispatch::TimeoutManager::Callback_OnDispatch(void) CoreMessagingXP.dll!Microsoft::CoreUI::Dispatch::Dispatcher::Callback_DispatchNextItem(void) CoreMessagingXP.dll!Microsoft::CoreUI::Dispatch::EventLoop::Callback_RunCoreLoop(enum Microsoft::CoreUI::Dispatch::RunMode) CoreMessagingXP.dll!Microsoft::CoreUI::Dispatch::SystemCoreMessaging::Callback_OnGroupDispatch(enum Microsoft::CoreUI::Dispatch::SystemCoreMessaging$GroupPriority,struct CFlat::Ref<struct System::IntPtr>) CoreMessagingXP.dll!Microsoft::CoreUI::Dispatch::SystemCoreMessaging::NoContext_GroupDispatchHandler(enum Microsoft::CoreUI::Dispatch::SystemCoreMessaging$GroupPriority,void *) CoreMessagingXP.dll!Microsoft::CoreUI::Dispatch::SystemCoreMessaging::NoContext_HighPriorityDispatchHandler(void *) CoreMessaging.dll!Microsoft__CoreUI__DispatchGroupHandler$CallbackThunk(class System::Delegate *) CoreMessaging.dll!Microsoft::CoreUI::DispatchGroupHandler::Invoke() 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() Microsoft.ui.xaml.dll!DirectUI::FrameworkApplication::RunDesktopWindowMessageLoop() Microsoft.ui.xaml.dll!DirectUI::FrameworkApplication::StartDesktop() Microsoft.ui.xaml.dll!DirectUI::FrameworkApplicationFactory::Start() [External Code] [Inline Frame] hostpolicy.dll!coreclr_t::execute_assembly(int) Line 89 at D:\workspace\_work\1\s\src\installer\corehost\cli\hostpolicy\coreclr.cpp(89) hostpolicy.dll!run_app_for_context(const hostpolicy_context_t & context, int argc, const wchar_t * * argv) Line 246 at D:\workspace\_work\1\s\src\installer\corehost\cli\hostpolicy\hostpolicy.cpp(246) hostpolicy.dll!run_app(const int argc, const wchar_t * * argv) Line 275 at D:\workspace\_work\1\s\src\installer\corehost\cli\hostpolicy\hostpolicy.cpp(275) hostpolicy.dll!corehost_main(const int argc, const wchar_t * * argv) Line 408 at D:\workspace\_work\1\s\src\installer\corehost\cli\hostpolicy\hostpolicy.cpp(408) hostfxr.dll!execute_app(const std::wstring & impl_dll_dir, corehost_init_t * init, const int argc, const wchar_t * * argv) Line 146 at D:\workspace\_work\1\s\src\native\corehost\fxr\fx_muxer.cpp(146) hostfxr.dll!anonymous namespace'::read_config_and_execute(const std::wstring & host_command, const host_startup_info_t & host_info, const std::wstring & app_candidate, const std::unordered_map<enum known_options,std::vector<std::wstring,std::allocator>,known_options_hash,std::equal_to,std::allocator<std::pair<enum known_options const ,std::vector<std::wstring,std::allocator>>>> & opts, int new_argc, const wchar_t new_argv, host_mode_t mode, wchar_t out_buffer, int buffer_size, int required_buffer_size) Line 520 at D:\workspace_work\1\s\src\native\corehost\fxr\fx_muxer.cpp(520) hostfxr.dll!fx_muxer_t::handle_exec_host_command(const std::wstring & host_command, const host_startup_info_t & host_info, const std::wstring & app_candidate, const std::unordered_map<enum known_options,std::vector<std::wstring,std::allocator>,known_options_hash,std::equal_to,std::allocator<std::pair<enum known_options const ,std::vector<std::wstring,std::allocator>>>> & opts, int argc, const wchar_t argv, int argoff, host_mode_t mode, wchar_t result_buffer, int buffer_size, int required_buffer_size) Line 1001 at D:\workspace_work\1\s\src\native\corehost\fxr\fx_muxer.cpp(1001) hostfxr.dll!fx_muxer_t::execute(const std::wstring host_command, const int argc, const wchar_t argv, const host_startup_info_t & host_info, wchar_t result_buffer, int buffer_size, int required_buffer_size) Line 566 at D:\workspace_work\1\s\src\native\corehost\fxr\fx_muxer.cpp(566) hostfxr.dll!hostfxr_main_startupinfo(const int argc, const wchar_t argv, const wchar_t host_path, const wchar_t dotnet_root, const wchar_t app_path) Line 61 at D:\workspace_work\1\s\src\native\corehost\fxr\hostfxr.cpp(61) Demo3.exe!exe_start(const int argc, const wchar_t argv) Line 236 at D:\workspace_work\1\s\src\installer\corehost\corehost.cpp(236) Demo3.exe!wmain(const int argc, const wchar_t * argv) Line 302 at D:\workspace_work\1\s\src\installer\corehost\corehost.cpp(302) [External Code]

<!-- Provide as many code-snippets or XAML snippets where appropriate. -->

## Expected behavior
No crashing

## Screenshots
![image](https://user-images.githubusercontent.com/9586533/122682778-48c12980-d1b0-11eb-9c28-aa577d2b4113.png)

## Environment
<!-- Check one or more of the following options with "x" -->

NuGet Package(s):

Package Version(s):

Windows 10 Build Number:

App min and target version:

Device form factor:

Visual Studio



## Additional context
**The app does not actually perform any sorting, it just follows the guidelines for implementing sorting and sets the ItemsSource to null and then back to the original list to mimic the sorting update process.** 
ghost commented 3 years ago

Hello omnilogix, thank you for opening an issue with us!

I have automatically added a "needs triage" label to help get things started. Our team will analyze and investigate the issue, and escalate it to the relevant team if possible. Other community members may also look into the issue and provide feedback 🙌

Kyaa-dost commented 3 years ago

@azchohfi is there any compatibility issue with the packages mentioned above? ⬆️

azchohfi commented 3 years ago

Yes @Kyaa-dost. @omnilogix 0.8 RC is not supported by the WCT. We will ship new packages that support 0.8 soon. Could you test this with Reunion 0.5? If the problem still exists, then it might be actually be an issue.

Marv51 commented 3 years ago

Crashes for me in 0.5.7 with the same exception.

azchohfi commented 3 years ago

@RBrid / @anawishnoff any idea?

Kyaa-dost commented 3 years ago

@azchohfi Thanks and yes certainly crashes with 0.5.

omnilogix commented 3 years ago

Could you test this with Reunion 0.5? If the problem still exists, then it might be actually be an issue.

Confirmed still crashes with Reunion 0.5.7

omnilogix commented 3 years ago

For what it's worth, I'm seeing this same exception stack for other scenarios of navigating and clicking in a WinUI 3 app. image

omnilogix commented 3 years ago

@Kyaa-dost This issue should probably be moved to a more appropriate repo. Although it is reproducible by clicking on the DataGrid, I am seeing this same exception stack (~AutoPeg) for may different crashes when interacting with the WinUI gui in general.

Kyaa-dost commented 3 years ago

@omnilogix Datagrid issue channels through here. Based on the testing above seems like the issue is isolated to Datagrid. @anawishnoff @RBrid can someone please investigate this issue? Thanks!

Marv51 commented 3 years ago

Any update on this? I'm still seeing this crash in 0.8.2