Plugin crashes on accessing dropdown after closing and re-opening in Bitwig

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;
}

AI tools are great, but they can encourage you to run before you can walk. There are lots of complicated concepts here. Pointers, Lambdas, Statics… with C++ you have to get some basic understanding if you hope to fix crashes todo with these things.

It’s not clear exactly what your crash is without a “stack trace” from the crash. I am a bit suspicious about the static IPopupMenu menu which is not a great way to declare the menu. Are you sure you don’t want your “root note” etc to be a parameter? You don’t need to serialize/deserialize strings manually then and it’s easier.

Why not make these things enum parameters and use a built it menu control to create the pop-up. See

for example

2 Likes

Thank you so much Oli, this is exactly what i wanted and it s so much cleaner! It worked out just fine. (I went for the generic dropdown)

1 Like