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 #5025

Closed
viniciuscabral opened this issue Jan 14, 2025 · 1 comment
Closed

ThemeSettings Crashing application #5025

viniciuscabral opened this issue Jan 14, 2025 · 1 comment

Comments

@viniciuscabral
Copy link

viniciuscabral commented Jan 14, 2025

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

Windows App SDK 1.6.3: 1.6.241114003

Packaging type

No response

Windows version

Windows 11 version 22H2 (22621, 2022 Update)

IDE

Visual Studio 2022

Additional context

No response

@codendone
Copy link
Contributor

We'll track this one via microsoft/microsoft-ui-xaml#10299.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants