Skip to content

Commit

Permalink
Fix an ownership probelm which caused WS Crash (#5071)
Browse files Browse the repository at this point in the history
WaveShaper is owned by SGE not by the SGE Skin Map, which
is fine, but it could lead to a RMB recreating a widget then
accidetntally deleting self from underneath. Fix

Closes #5056
  • Loading branch information
baconpaul authored Sep 13, 2021
1 parent aba7ad8 commit 0313dd7
Showing 1 changed file with 35 additions and 16 deletions.
51 changes: 35 additions & 16 deletions src/gui/SurgeGUIEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4463,8 +4463,8 @@ SurgeGUIEditor::layoutComponentForSkin(std::shared_ptr<Surge::GUI::Skin::Control
int lfo_id = p->ctrlgroup_entry - ms_lfo1;
if ((lfo_id >= 0) && (lfo_id < n_lfos))
{
lfoDisplay =
componentForSkinSession<Surge::Widgets::LFOAndStepDisplay>(skinCtrl->sessionid);
if (!lfoDisplay)
lfoDisplay = std::make_unique<Surge::Widgets::LFOAndStepDisplay>();
lfoDisplay->setBounds(skinCtrl->getRect());
lfoDisplay->setSkin(currentSkin, bitmapStore, skinCtrl);
lfoDisplay->setTag(p->id + start_paramtags);
Expand Down Expand Up @@ -4550,7 +4550,22 @@ SurgeGUIEditor::layoutComponentForSkin(std::shared_ptr<Surge::GUI::Skin::Control

if (skinCtrl->defaultComponent == Surge::Skin::Components::NumberField)
{
auto pbd = componentForSkinSession<Surge::Widgets::NumberField>(skinCtrl->sessionid);
// some are managed outside of the skin session management
std::unique_ptr<Surge::Widgets::NumberField> pbd;
switch (p->ctrltype)
{
case ct_polylimit:
pbd = std::move(polydisp);
break;
case ct_midikey_or_channel:
pbd = std::move(splitpointControl);
break;
default:
break;
}

if (!pbd)
pbd = componentForSkinSession<Surge::Widgets::NumberField>(skinCtrl->sessionid);
pbd->addListener(this);
pbd->setSkin(currentSkin, bitmapStore, skinCtrl);
pbd->setTag(tag);
Expand Down Expand Up @@ -4731,24 +4746,28 @@ SurgeGUIEditor::layoutComponentForSkin(std::shared_ptr<Surge::GUI::Skin::Control
if (!p)
return nullptr;

/*
* This doesn't participate in the juceSkinComponents but that's OK
*/
auto rect = skinCtrl->getRect();
auto hsw = componentForSkinSession<Surge::Widgets::WaveShaperSelector>(skinCtrl->sessionid);
hsw->addListener(this);
hsw->setStorage(&(synth->storage));
hsw->setSkin(currentSkin, bitmapStore, skinCtrl);
hsw->setTag(p->id + start_paramtags);
hsw->setBounds(rect);
hsw->setValue(p->get_value_f01());

if (!waveshaperSelector)
waveshaperSelector = std::make_unique<Surge::Widgets::WaveShaperSelector>();

waveshaperSelector->addListener(this);
waveshaperSelector->setStorage(&(synth->storage));
waveshaperSelector->setSkin(currentSkin, bitmapStore, skinCtrl);
waveshaperSelector->setTag(p->id + start_paramtags);
waveshaperSelector->setBounds(rect);
waveshaperSelector->setValue(p->get_value_f01());

auto *parm = dynamic_cast<ParameterDiscreteIndexRemapper *>(p->user_data);
if (parm && parm->supportsTotalIndexOrdering())
hsw->setIntOrdering(parm->totalIndexOrdering());

setAccessibilityInformationByParameter(hsw.get(), p, "Select");
frame->getControlGroupLayer(cg_FILTER)->addAndMakeVisible(*hsw);
nonmod_param[paramIndex] = hsw.get();
waveshaperSelector->setIntOrdering(parm->totalIndexOrdering());

waveshaperSelector = std::move(hsw);
setAccessibilityInformationByParameter(waveshaperSelector.get(), p, "Select");
frame->getControlGroupLayer(cg_FILTER)->addAndMakeVisible(*waveshaperSelector);
nonmod_param[paramIndex] = waveshaperSelector.get();

return dynamic_cast<Surge::GUI::IComponentTagValue *>(waveshaperSelector.get());
}
Expand Down

0 comments on commit 0313dd7

Please sign in to comment.