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

ThemeSettings Crashing application #10299

Open
viniciuscabral opened this issue Jan 14, 2025 · 0 comments
Open

ThemeSettings Crashing application #10299

viniciuscabral opened this issue Jan 14, 2025 · 0 comments
Labels
bug Something isn't working Crash whenever user reports a crash or app freeze

Comments

@viniciuscabral
Copy link

Describe the bug

For some reason when I use ThemeSettings to watch the Changed event, the application crashes with an internal error from SDK.
It happens in two scenarios:
1 - When I use ThemeSettings like a local variable
2 - When I use ThemeSettings like a global variable in a single instance class

Steps to reproduce the bug

I create an app with two Pages and move back and forth between them.

First scenario you can use it like that in the Loaded event in the second Page.

 if (this.XamlRoot != null && this.XamlRoot.ContentIslandEnvironment != null)
 {
     WindowId myWindowId = this.XamlRoot.ContentIslandEnvironment.AppWindowId;
    var _themeSettings = ThemeSettings.CreateForWindowId(myWindowId);

     if (_themeSettings != null)
     {
         _themeSettings.Changed += ThemeSettings_Changed;
     }
 }

In some moments the App Crashes...

The second scenario just replaces var _themeSettings for a global variable and moves the code to a singleton class. Both crashes the same way.

I suppose it can happen because the Changed event isn't explicitly unsubscribed... But I believe it's an unhandled exception in the SDK source code.
To solve the problem by now, I'm checking if _themeSettings is not null before CreateForWindowId and Unbscribe the Changed event in the Unload page Event, but I'm not sure if other crashes can reside.

Expected behavior

Do not crash the app.

Screenshots

Image
No valuable information actually.

NuGet package version

WinUI 3 - Windows App SDK 1.6.3: 1.6.241114003

Windows version

Windows 11 (22H2): Build 22621

Additional context

No response

@viniciuscabral viniciuscabral added the bug Something isn't working label Jan 14, 2025
@microsoft-github-policy-service microsoft-github-policy-service bot added the needs-triage Issue needs to be triaged by the area owners label Jan 14, 2025
@karkarl karkarl added Crash whenever user reports a crash or app freeze and removed needs-triage Issue needs to be triaged by the area owners labels Jan 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Crash whenever user reports a crash or app freeze
Projects
None yet
Development

No branches or pull requests

2 participants