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

Fix: Fixed possible System.NullReferenceException in ThemeHelper #12175

Merged
merged 3 commits into from
Apr 23, 2023

Conversation

yaira2
Copy link
Member

@yaira2 yaira2 commented Apr 23, 2023

Resolved / Related Issues

  • Were these changes approved in an issue or discussion with the project maintainers? In order to prevent extra work, feature requests and changes to the codebase must be approved before the pull request will be reviewed. This prevents extra work for the contributors and maintainers.
    Closes #issue...

Validation
How did you test these changes?

  • Did you build the app and test your changes?
  • Did you check for accessibility? You can use Accessibility Insights for this.
  • Did you remove any strings from the en-us resource file?
    • Did you search the solution to see if the string is still being used?
  • Did you implement any design changes to an existing feature?
    • Was this change approved?
  • Are there any other steps that were used to validate these changes?
    1. Open app ...
    2. Click settings button ...

Screenshots (optional)
image

@yaira2 yaira2 marked this pull request as draft April 23, 2023 19:43
@hishitetsu
Copy link
Member

public static void Initialize()
{
// Save reference as this might be null when the user is in another app
currentApplicationWindow = App.Window;
// Set TitleBar background color
titleBar = App.GetAppWindow(currentApplicationWindow).TitleBar;

If currentApplicationWindow is null, a NullReferenceException may occur at line 52.

@yaira2 yaira2 marked this pull request as ready for review April 23, 2023 23:27
@yaira2
Copy link
Member Author

yaira2 commented Apr 23, 2023

@hishitetsu thanks!

@yaira2 yaira2 merged commit a97fbbf into service/2.4.67 Apr 23, 2023
Comment on lines +66 to +67
if (currentApplicationWindow is null)
return;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If currentApplicationWindow is null here, shouldn't we try initialize again?

Copy link
Member Author

@yaira2 yaira2 Apr 23, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't it get stuck in a loop?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should try one time every the event raised.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm curious what you have in mind, would you add a Boolean to keep track?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have like this in mind.

		private static async void UiSettings_ColorValuesChanged(UISettings sender, object args)
		{
			// Make sure we have a reference to our window so we dispatch a UI change
			if (currentApplicationWindow is null)
			{
				currentApplicationWindow = App.Window;

				if (currentApplicationWindow is not null)
					titleBar = App.GetAppWindow(currentApplicationWindow).TitleBar;
				else
					return;
			}

			// Dispatch on UI thread so that we have a current appbar to access and change
			await currentApplicationWindow.DispatcherQueue.EnqueueAsync(ApplyTheme);
		}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hishitetsu can you open a PR?

@yaira2 yaira2 deleted the ya/ThemeHelper branch April 23, 2023 23:47
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

Successfully merging this pull request may close these issues.

2 participants