Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't set ProtectedCursor in DependencyProperty PropertyChangedCallback - Access Violation #7062

Closed
1 of 2 tasks
michael-hawker opened this issue May 5, 2022 · 4 comments
Closed
1 of 2 tasks
Labels
bug Something isn't working product-winui3 WinUI 3 issues team-Markup Issue for the Markup team wct

Comments

@michael-hawker
Copy link
Collaborator

michael-hawker commented May 5, 2022

Describe the bug

Tested on both latest 1.1.0-preview3 (not an option in dropdown below) and 1.0.1,

I'm hitting a 0xC0000005: Access violation reading location 0x0000000000000000. error when trying to set the ProtectedCursor on my derived control. I'm trying to update our new refactor of GridSplitter and related controls in the Toolkit to work with WinUI 3 from this PR here CommunityToolkit/WindowsCommunityToolkit#4083 (related to issue #4509 here as well).

We'd like to showcase this component in our new Labs setup. Seems more severe of an issue than previously reported #6058.

Interesting to note is that if I change this value within OnApplyTemplate it seems to work fine. However, when being called as a result of the XAML DependencyProperty PropertyChangedCallback - updating it fails with this error.

I tried to use a DispatcherQueue within the callback, but that resulted in the same error. (Even though this should already be still on the UI thread, so I wouldn't expect to have to do this here.)

Steps to reproduce the bug

Derive a control and try and set the ProtectedCursor property:

ProtectedCursor = InputSystemCursor.Create(InputSystemCursorShape.SizeNorthSouth);

Move this to a DependencyPropertyChanged callback, see error.

Happy to add someone to our repo and point them to the commit where we can reproduce this in Labs.

Expected behavior

Should not crash and set the cursor to the specified value.

Screenshots

No response

NuGet package version

WinUI 3 - Windows App SDK 1.1 Preview 2: 1.1.0-preview3

Windows app type

  • UWP
  • Win32

Device form factor

Desktop

Windows version

Windows 10 (21H2): Build 19044

Additional context

Exception thrown at 0x00007FFDB995F223 (Microsoft.ui.xaml.dll) in SizerBase.WinAppSdk.exe: 0xC0000005: Access violation reading location 0x0000000000000000.
 	Microsoft.ui.xaml.dll!CInputServices::SetCursor()	Unknown
 	Microsoft.ui.xaml.dll!CInputServices::UpdateCursor()	Unknown
 	Microsoft.ui.xaml.dll!CUIElement::SetValue()	Unknown
 	Microsoft.ui.xaml.dll!CFrameworkElement::SetValue()	Unknown
 	Microsoft.ui.xaml.dll!CControl::SetValue()	Unknown
 	Microsoft.ui.xaml.dll!DirectUI::DependencyObject::SetValueCore()	Unknown
 	Microsoft.ui.xaml.dll!DirectUI::DependencyObject::SetValueByKnownIndex()	Unknown
 	[Managed to Native Transition]	
 	Microsoft.WinUI.dll!ABI.Microsoft.UI.Xaml.IUIElementProtectedMethods.set_ProtectedCursor(WinRT.IObjectReference _obj, Microsoft.UI.Input.InputCursor value)	Unknown
 	Microsoft.WinUI.dll!Microsoft.UI.Xaml.UIElement.ProtectedCursor.set(Microsoft.UI.Input.InputCursor value)	Unknown
>	CommunityToolkit.Labs.WinUI.SizerBase.dll!CommunityToolkit.Labs.WinUI.SizerBase.OnOrientationPropertyChanged(Microsoft.UI.Xaml.DependencyObject d, Microsoft.UI.Xaml.DependencyPropertyChangedEventArgs e) Line 111	C#
 	Microsoft.WinUI.dll!ABI.Microsoft.UI.Xaml.PropertyChangedCallback.Do_Abi_Invoke(System.IntPtr thisPtr, System.IntPtr d, System.IntPtr e)	Unknown
 	[Native to Managed Transition]	
 	Microsoft.ui.xaml.dll!DirectUI::DependencyObject::NotifyPropertyChanged()	Unknown
 	Microsoft.ui.xaml.dll!CDependencyObject::NotifyPropertyChanged()	Unknown
 	Microsoft.ui.xaml.dll!CDependencyObject::SetEffectiveValue()	Unknown
 	Microsoft.ui.xaml.dll!CDependencyObject::UpdateEffectiveValue()	Unknown
 	Microsoft.ui.xaml.dll!CDependencyObject::SetValue()	Unknown
 	Microsoft.ui.xaml.dll!CUIElement::SetValue()	Unknown
...

Working stack:

>	CommunityToolkit.Labs.WinUI.SizerBase.dll!CommunityToolkit.Labs.WinUI.SizerBase.OnOrientationPropertyChanged(Microsoft.UI.Xaml.DependencyObject d, Microsoft.UI.Xaml.DependencyPropertyChangedEventArgs e) Line 111	C#
 	CommunityToolkit.Labs.WinUI.SizerBase.dll!CommunityToolkit.Labs.WinUI.SizerBase.OnApplyTemplate() Line 124	C#
 	Microsoft.WinUI.dll!Microsoft.UI.Xaml.FrameworkElement.Microsoft.UI.Xaml.IFrameworkElementOverrides.OnApplyTemplate()	Unknown
 	Microsoft.WinUI.dll!ABI.Microsoft.UI.Xaml.IFrameworkElementOverrides.Do_Abi_OnApplyTemplate_2(System.IntPtr thisPtr)	Unknown
 	[Native to Managed Transition]	
 	Microsoft.ui.xaml.dll!DirectUI::FrameworkElementGenerated::OnApplyTemplateProtected()	Unknown
 	Microsoft.ui.xaml.dll!DirectUI::FrameworkElement::OnApplyTemplateFromCore()	Unknown
 	Microsoft.ui.xaml.dll!CFrameworkElement::InvokeApplyTemplate()	Unknown
 	Microsoft.ui.xaml.dll!CFrameworkElement::MeasureCore()	Unknown
 	Microsoft.ui.xaml.dll!CUIElement::MeasureInternal()	Unknown
 	Microsoft.ui.xaml.dll!CUIElement::Measure()	Unknown
 	Microsoft.ui.xaml.dll!CGrid::MeasureCell()	Unknown
 	Microsoft.ui.xaml.dll!CGrid::MeasureCellsGroup()	Unknown
 	Microsoft.ui.xaml.dll!CGrid::MeasureOverride()	Unknown
 	Microsoft.ui.xaml.dll!CFrameworkElement::MeasureCore()	Unknown
 	Microsoft.ui.xaml.dll!CUIElement::MeasureInternal()	Unknown
 	Microsoft.ui.xaml.dll!CUIElement::Measure()	Unknown
 	Microsoft.ui.xaml.dll!DirectUI::UIElementGenerated::Measure()	Unknown
 	Microsoft.ui.xaml.dll!DirectUI::Page::MeasureOverride()	Unknown
...

Related microsoft/WindowsAppSDK#1816

@michael-hawker michael-hawker added bug Something isn't working wct labels May 5, 2022
@ghost ghost added the needs-triage Issue needs to be triaged by the area owners label May 5, 2022
michael-hawker added a commit to CommunityToolkit/Labs-Windows that referenced this issue May 5, 2022
@michael-hawker michael-hawker added the product-winui3 WinUI 3 issues label May 5, 2022
@MikeHillberg
Copy link
Contributor

I think the issue is that it can only be called when it's in the live tree, so OnApplyTemplate or the Loaded event handler are workarounds.

@michael-hawker
Copy link
Collaborator Author

michael-hawker commented May 6, 2022

@MikeHillberg thanks, If I ignore the first change from the DependencyProperty being set in XAML, I can still grab the value and call to set it in OnApplyTemplate. Will see how that holds up with some more testing and when dynamically changing the property at runtime which is trying to update this.

Opened a doc bug to add a note about this for now.

michael-hawker added a commit to CommunityToolkit/Labs-Windows that referenced this issue May 6, 2022
michael-hawker added a commit to CommunityToolkit/Labs-Windows that referenced this issue May 10, 2022
@ojhad ojhad added the team-Markup Issue for the Markup team label May 10, 2022
michael-hawker added a commit to CommunityToolkit/Labs-Windows that referenced this issue May 11, 2022
michael-hawker added a commit to CommunityToolkit/Labs-Windows that referenced this issue May 12, 2022
michael-hawker added a commit to CommunityToolkit/Labs-Windows that referenced this issue May 12, 2022
@bpulliam bpulliam removed the needs-triage Issue needs to be triaged by the area owners label Dec 6, 2022
@michael-hawker
Copy link
Collaborator Author

Looks like the doc issue is still open, so bumping based on #8638

@codendone
Copy link
Contributor

This crash is fixed in 1.4-preview1 and was also serviced to 1.3 in 1.3.230602002.

Martin1994 pushed a commit to Martin1994/Labs-Windows that referenced this issue Sep 2, 2023
Gaoyifei1011 added a commit to Gaoyifei1011/GetStoreApp that referenced this issue Sep 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working product-winui3 WinUI 3 issues team-Markup Issue for the Markup team wct
Projects
None yet
Development

No branches or pull requests

5 participants