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

[Settings > PT Run > PluginAdditionalOptions] Fix crash on empty number box #32832

Merged
merged 4 commits into from
May 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,15 @@ public double NumberValue
get => _additionalOption.NumberValue;
set
{
if (value != _additionalOption.NumberValue)
if (double.IsNaN(value))
{
// If the user clears the NumberBox and presses enter or moves focus away then `value` converted to double results in `double.NaN`. This crashes the settings app. (https://github.com/microsoft/PowerToys/issues/32738#issuecomment-2105983967)
// To prevent the crash and provide a nice user experience we reset the NumberBox to the last valid value. This happens by sending a `NotifyPropertyChanged()` command and let the NumberBox reload its value.
// (Yes we could use 0, but this needs additional code for checking 0 against min and max.
// And yes we could also use the min value of the NumberBox, but this is not user friendly as the minimum value of NumberBox can be `double.MinValue`.)
NotifyPropertyChanged();
}
else if (value != _additionalOption.NumberValue)
{
_additionalOption.NumberValue = value;
NotifyPropertyChanged();
Expand Down