1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-10 23:44:24 +00:00

Slider: Avoid updating internal Value when old and new values are both NaN

Without this change in place, setting the Value to NaN can cause a stack
overflow because the old and new values always compare unequal, causing
new change notifications to be sent.
This commit is contained in:
reuk 2024-06-03 12:01:08 +01:00
parent 2a264390e8
commit 182dd84e59
No known key found for this signature in database
GPG key ID: FCB43929F012EE5C

View file

@ -225,7 +225,10 @@ public:
// Need to do this comparison because the Value will use equalsWithSameType to compare
// the new and old values, so will generate unwanted change events if the type changes.
// Cast to double before comparing, to prevent comparing as another type (e.g. String).
if (! approximatelyEqual (static_cast<double> (currentValue.getValue()), newValue))
// We also want to avoid sending a notification if both new and old values are NaN.
const auto asDouble = static_cast<double> (currentValue.getValue());
if (! (approximatelyEqual (asDouble, newValue) || (std::isnan (asDouble) && std::isnan (newValue))))
currentValue = newValue;
updateText();