Skip to content

Commit

Permalink
Guard all our lambdas with SafePointers
Browse files Browse the repository at this point in the history
We had a bunch of lambdas which referenced 'this' rather than
'that = SafePointer' for callbacks on timers and I think
perhaps one of those is what caused the very occasional crash-on
close in reaper reported in surge-synthesizer#6558 so review them and push a change.

Keep the issue open for a bit while we look for crashes tho
  • Loading branch information
baconpaul committed Aug 22, 2022
1 parent b8b5a08 commit 60ffd41
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/surge-xt/gui/SurgeGUIEditorValueCallbacks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2989,14 +2989,14 @@ void SurgeGUIEditor::valueChanged(Surge::GUI::IComponentTagValue *control)
if (tag == tag_action_undo)
{
undoManager()->undo();
juce::Timer::callAfterDelay(25, [this, control]() { control->setValue(0); });
juce::Timer::callAfterDelay(25, [control]() { control->setValue(0); });
return;
}

if (tag == tag_action_redo)
{
undoManager()->redo();
juce::Timer::callAfterDelay(25, [this, control]() { control->setValue(0); });
juce::Timer::callAfterDelay(25, [control]() { control->setValue(0); });
return;
}

Expand Down
7 changes: 6 additions & 1 deletion src/surge-xt/gui/overlays/OverlayWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,12 @@ struct TearOutWindow : public juce::DocumentWindow, public Surge::GUI::SkinConsu

outstandingMoves++;
// writing every move would be "bad". Add a 1 second delay.
juce::Timer::callAfterDelay(1000, [this]() { this->moveUpdate(); });
juce::Timer::callAfterDelay(1000, [that = juce::Component::SafePointer(this)]() {
if (that)
{
that->moveUpdate();
}
});
}

void moveUpdate()
Expand Down
9 changes: 6 additions & 3 deletions src/surge-xt/gui/overlays/TypeinParamEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,9 +213,12 @@ void TypeinParamEditor::textEditorReturnKeyPressed(juce::TextEditor &te)
{
wasInputInvalid = true;
repaint();
juce::Timer::callAfterDelay(5000, [this]() {
wasInputInvalid = false;
repaint();
juce::Timer::callAfterDelay(5000, [that = juce::Component::SafePointer(this)]() {
if (that)
{
that->wasInputInvalid = false;
that->repaint();
}
});
}
}
Expand Down
5 changes: 4 additions & 1 deletion src/surge-xt/gui/widgets/MultiSwitch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,10 @@ void MultiSwitch::mouseDown(const juce::MouseEvent &event)

if (draggable)
{
juce::Timer::callAfterDelay(250, [this]() { this->setCursorToArrow(); });
juce::Timer::callAfterDelay(250, [that = juce::Component::SafePointer(this)]() {
if (that)
that->setCursorToArrow();
});
}

mouseDownLongHold(event);
Expand Down
19 changes: 14 additions & 5 deletions src/surge-xt/gui/widgets/PatchSelector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -367,9 +367,12 @@ void PatchSelector::mouseDown(const juce::MouseEvent &e)

stuckHover = true;
menu.showMenuAsync(sge->popupMenuOptions(favoritesRect.getBottomLeft()),
[this](int) {
stuckHover = false;
endHover();
[that = juce::Component::SafePointer(this)](int) {
if (that)
{
that->stuckHover = false;
that->endHover();
}
});
}

Expand Down Expand Up @@ -1225,7 +1228,10 @@ void PatchSelector::toggleTypeAheadSearch(bool b)

if (!enable)
{
juce::Timer::callAfterDelay(250, [this]() { this->enableTypeAheadIfReady(); });
juce::Timer::callAfterDelay(250, [that = juce::Component::SafePointer(this)]() {
if (that)
that->enableTypeAheadIfReady();
});
}
else
{
Expand Down Expand Up @@ -1277,7 +1283,10 @@ void PatchSelector::enableTypeAheadIfReady()
}
else
{
juce::Timer::callAfterDelay(250, [this]() { this->enableTypeAheadIfReady(); });
juce::Timer::callAfterDelay(250, [that = juce::Component::SafePointer(this)]() {
if (that)
that->enableTypeAheadIfReady();
});
}
}

Expand Down

0 comments on commit 60ffd41

Please sign in to comment.