diff --git a/modules/juce_gui_basics/buttons/juce_Button.cpp b/modules/juce_gui_basics/buttons/juce_Button.cpp index e996545680..44af5cde4f 100644 --- a/modules/juce_gui_basics/buttons/juce_Button.cpp +++ b/modules/juce_gui_basics/buttons/juce_Button.cpp @@ -165,14 +165,22 @@ void Button::setToggleState (const bool shouldBeOn, const NotificationType notif { if (shouldBeOn != lastToggleState) { + WeakReference deletionWatcher (this); + + if (shouldBeOn) + { + turnOffOtherButtonsInGroup (dontSendNotification); + + if (deletionWatcher == nullptr) + return; + } + if (getToggleState() != shouldBeOn) // this test means that if the value is void rather than explicitly set to isOn = shouldBeOn; // false, it won't be changed unless the required value is true. lastToggleState = shouldBeOn; repaint(); - WeakReference deletionWatcher (this); - if (notification != dontSendNotification) { // async callbacks aren't possible here @@ -184,14 +192,6 @@ void Button::setToggleState (const bool shouldBeOn, const NotificationType notif return; } - if (lastToggleState) - { - turnOffOtherButtonsInGroup (dontSendNotification); - - if (deletionWatcher == nullptr) - return; - } - if (notification != dontSendNotification) sendStateMessage(); }