I m facing a challenge where my MacOS VST3 target plugin crashes each time it s closed and re-opened in the DAW (Bitwig in my case) on making a change to one of my dropdown menus. For brevity, I m sharing a bare minimum example of my set up (and what I have tried so far). I have no background in C++ hence I may very well be missing some very obvious things. Hence looking for some guidance.
I have a MIDI Effect plugin which has a private member such as
private:
std::string mRootNote = "C";
To edit this default value I have a dropdown UI that one can click and select another root note. It looks something like this
pGraphics->AttachControl(new IVButtonControl({10, 35, 10 + 45, 35 + 40}, [this, pGraphics](IControl* pCaller){
SplashClickActionFunc(pCaller);
static IPopupMenu menu {"Menu", {"C", "D", "E", "F", "G", "A", "B"}, [this, pCaller](IPopupMenu* pMenu) {
auto* itemChosen = pMenu->GetChosenItem();
if(itemChosen) {
mRootNote = itemChosen->GetText();
pCaller->As<IVButtonControl>()->SetValueStr(mRootNote.c_str());
}
}
};
float x, y;
pGraphics->GetMouseDownPoint(x, y);
pGraphics->CreatePopupMenu(*pCaller, menu, x, y);
}, "", style.WithValueText(IText(24.f, EVAlign::Middle)), false, true), kNoTag, "vcontrols");
pGraphics->GetControl(pGraphics->NControls()-1)->As<IVButtonControl>()->SetValueStr(mRootNote.c_str());
This works perfectly fine when the plugin is open and I can change the root note and continue with my functionality. But if I close the plugin window, re-open it and then again access the dropdown to change it s value, the plugin crashes. I havent been able to successfully make DBGMSG work in the context of Bitwig which is why I dont know what could be crashing the plugin.
Could someone please guide me in this matter. I used the ChatGPT bot for iPlug2 and Copilot so far to create my plugin and it s going really well so far. The issue I outlined here in this post is causing some grief otherwise. I ve already tried the following but it didnt help.
void MyMidiPlugin::OnStateReset()
{
// Initialize the state of the plugin
mRootNote = "C";
mOctave = "3";
mScaleName = "ionian";
mPatternCombination = "A";
}
bool MyMidiPlugin::SerializeState(IByteChunk& chunk) const
{
// Save the state of the plugin
chunk.PutStr(mRootNote.c_str());
chunk.PutStr(mOctave.c_str());
chunk.PutStr(mScaleName.c_str());
chunk.PutStr(mPatternCombination.c_str());
return true;
}
int MyMidiPlugin::DeserializeState(const IByteChunk& chunk, int startPos)
{
// Restore the state of the plugin
WDL_String wdlStr;
startPos = chunk.GetStr(wdlStr, startPos);
mRootNote = wdlStr.Get();
return startPos;
}