From 182dd84e59fe1c7ba7abb68d8a6bad90df9a318e Mon Sep 17 00:00:00 2001 From: reuk Date: Mon, 3 Jun 2024 12:01:08 +0100 Subject: [PATCH] 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. --- modules/juce_gui_basics/widgets/juce_Slider.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/modules/juce_gui_basics/widgets/juce_Slider.cpp b/modules/juce_gui_basics/widgets/juce_Slider.cpp index 6c185d6cd9..d28d5bbb82 100644 --- a/modules/juce_gui_basics/widgets/juce_Slider.cpp +++ b/modules/juce_gui_basics/widgets/juce_Slider.cpp @@ -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 (currentValue.getValue()), newValue)) + // We also want to avoid sending a notification if both new and old values are NaN. + const auto asDouble = static_cast (currentValue.getValue()); + + if (! (approximatelyEqual (asDouble, newValue) || (std::isnan (asDouble) && std::isnan (newValue)))) currentValue = newValue; updateText();