Skip to content

Commit

Permalink
Prevent setting toggle state after object deletion
Browse files Browse the repository at this point in the history
  • Loading branch information
jameshball committed Aug 21, 2024
1 parent 00b0c31 commit 2f9cb2b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
4 changes: 4 additions & 0 deletions Source/components/EffectsListComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@

EffectsListComponent::EffectsListComponent(DraggableListBox& lb, AudioEffectListBoxItemData& data, int rn, Effect& effect) : DraggableListBoxItem(lb, data, rn),
effect(effect), audioProcessor(data.audioProcessor), editor(data.editor) {
if (effect.enabled == nullptr) {
DBG("Effect enabled is null");
}

auto parameters = effect.parameters;
for (int i = 0; i < parameters.size(); i++) {
std::shared_ptr<EffectComponent> effectComponent = std::make_shared<EffectComponent>(audioProcessor, effect, i);
Expand Down
9 changes: 7 additions & 2 deletions Source/components/SwitchButton.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,11 @@ class SwitchButton : public juce::Button, public juce::AudioProcessorParameter::
}

void parameterValueChanged(int parameterIndex, float newValue) override {
juce::MessageManager::callAsync([this]() {
setToggleState(parameter->getBoolValue(), juce::NotificationType::dontSendNotification);
juce::WeakReference<SwitchButton> weakThis = this;
juce::MessageManager::callAsync([weakThis, this]() {
if (weakThis != nullptr) {
setToggleState(parameter->getBoolValue(), juce::NotificationType::dontSendNotification);
}
});
}

Expand Down Expand Up @@ -174,6 +177,8 @@ class SwitchButton : public juce::Button, public juce::AudioProcessorParameter::
bool prevToggleState = false;

BooleanParameter* parameter = nullptr;

JUCE_DECLARE_WEAK_REFERENCEABLE(SwitchButton)
};

} // namespace jux

0 comments on commit 2f9cb2b

Please sign in to comment.