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

[SamplesApp] NullReferenceException setting cursors #15818

Open
spouliot opened this issue Mar 8, 2024 · 6 comments
Open

[SamplesApp] NullReferenceException setting cursors #15818

spouliot opened this issue Mar 8, 2024 · 6 comments
Labels
area/skia ✏️ Categorizes an issue or PR as relevant to Skia kind/bug Something isn't working platform/macos 🍏 Categorizes an issue or PR as relevant to the macOS platform

Comments

@spouliot
Copy link
Contributor

spouliot commented Mar 8, 2024

Current behavior

Debug Output shows

Exception thrown: 'System.NullReferenceException' in SamplesApp.Skia.dll
fail: Microsoft.UI.Xaml.UIElement[0]
      Failed to raise 'TappedEvent': System.NullReferenceException: Object reference not set to an instance of an object.
         at SamplesApp.Wasm.Windows_UI_Core.SetCursor.ResetTapped(Object sender, TappedRoutedEventArgs e) in /Users/poupou/git/external/uno/uno/src/SamplesApp/UITests.Shared/Windows_UI_Core/SetCursor.xaml.cs:line 63
         at SamplesApp.Wasm.Windows_UI_Core.SetCursor.<>c__DisplayClass11_0.<InitializeComponent>b__7(Object ResetTapped_sender, TappedRoutedEventArgs ResetTapped_e) in /Users/poupou/git/external/uno/uno/src/SamplesApp/SamplesApp.Skia/Uno.UI.SourceGenerators/Uno.UI.SourceGenerators.XamlGenerator.XamlCodeGenerator/SetCursor_17f3bfdba1899721a939a7e34569b374.cs:line 108
         at Microsoft.UI.Xaml.UIElement.InvokeHandler(Object handler, RoutedEventArgs args) in /Users/poupou/git/external/uno/uno/src/Uno.UI/UI/Xaml/UIElement.RoutedEvents.cs:line 977
         at Microsoft.UI.Xaml.UIElement.RaiseEvent(RoutedEvent routedEvent, RoutedEventArgs args, BubblingContext ctx) in /Users/poupou/git/external/uno/uno/src/Uno.UI/UI/Xaml/UIElement.RoutedEvents.cs:line 697
         at Microsoft.UI.Xaml.UIElement.SafeRaiseEvent(RoutedEvent routedEvent, RoutedEventArgs args, BubblingContext ctx) in /Users/poupou/git/external/uno/uno/src/Uno.UI/UI/Xaml/UIElement.RoutedEvents.cs:line 646

At line 55 of SetCursor.xaml.cs the value of Microsoft.UI.Xaml.Window.Current.CoreWindow is null which throws the `

Microsoft.UI.Xaml.Window.Current.CoreWindow.PointerCursor = new global::Windows.UI.Core.CoreCursor((global::Windows.UI.Core.CoreCursorType)Box.SelectedItem, 0);

Expected behavior

No exception.

How to reproduce it (as minimally and precisely as possible)

  1. Build and execute SampleApp.
  2. Select the SetCursor page
  3. Select a cursor (combobox)

The cursor does not change (to the selected cursor name) and an exception is logged (see Debug Output).

Workaround

None.

Works on UWP/WinUI

None

Environment

No response

NuGet package version(s)

No response

Affected platforms

Skia (GTK on Linux/macOS/Windows)

IDE

No response

IDE version

No response

Relevant plugins

No response

Anything else we need to know?

No response

@spouliot spouliot added kind/bug Something isn't working triage/untriaged Indicates an issue requires triaging or verification difficulty/tbd Categorizes an issue for which the difficulty level needs to be defined. labels Mar 8, 2024
@ramezgerges
Copy link
Contributor

This is a problem on WinUI, which deprecated Window.Current. It will work fine on the uwp tree. To set the cursor on WinUi (and uno), use ProtectedCursor, which I implemented recently.

@MartinZikmund MartinZikmund changed the title [SamplesApp] NullReferenceException setting cursors [SamplesApp] NullReferenceException setting cursors May 3, 2024
@MartinZikmund
Copy link
Member

The suggestion from @ramezgerges is correct solution. CoreWindow will always be null in Uno.WinUI

@spouliot
Copy link
Contributor Author

The issue was more a reminder to somehow [1] fix SampleApp than how to implement the new code for cursors (which already exists) 😄

[1] maybe just tell which the other test that covers the new code ? not sure how it's being handled for similar cases...

@ramezgerges
Copy link
Contributor

@spouliot there is a ProtectedCursor sample if I remember correctly.

@MartinZikmund MartinZikmund reopened this Jul 16, 2024
@MartinZikmund
Copy link
Member

Ah sorry, didn't realize ProtectedCursor might not be working on macOS yet, reopened for now then

@MartinZikmund MartinZikmund added platform/macos 🍏 Categorizes an issue or PR as relevant to the macOS platform area/skia ✏️ Categorizes an issue or PR as relevant to Skia and removed triage/untriaged Indicates an issue requires triaging or verification difficulty/tbd Categorizes an issue for which the difficulty level needs to be defined. labels Jul 16, 2024
@spouliot
Copy link
Contributor Author

@ramezgerges yes, I know there is :)

@MartinZikmund no, it's implemented/working on macOS :)

However anyone trying SampleApp might not know which test to use for cursors (I did not the first time).

Having the old test fail makes it look like cursor support is broken or incomplete.

Maybe that old test should be #if out when building for WinUI ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/skia ✏️ Categorizes an issue or PR as relevant to Skia kind/bug Something isn't working platform/macos 🍏 Categorizes an issue or PR as relevant to the macOS platform
Projects
None yet
Development

No branches or pull requests

3 participants