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

**URL:** <https://iplug2.discourse.group/t/plugin-crashes-on-accessing-dropdown-after-closing-and-re-opening-in-bitwig/982>\
**Category:** macOS\
**Created:** [15 February 2025 22:39 UTC](https://iplug2.discourse.group/t/plugin-crashes-on-accessing-dropdown-after-closing-and-re-opening-in-bitwig/982 "2025-02-15T22:39:15Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![walmik](https://yyz2.discourse-cdn.com/free1/user_avatar/iplug2.discourse.group/walmik/32/393_2.png) [@walmik](https://iplug2.discourse.group/u/walmik)\
**Post date:** [15 February 2025 22:39 UTC](https://iplug2.discourse.group/t/plugin-crashes-on-accessing-dropdown-after-closing-and-re-opening-in-bitwig/982/1 "2025-02-15T22:39:15Z")

</div>

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

```auto
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

```auto
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.

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

```

---

<div class="post-metadata">

**Author:** ![olilarkin](https://yyz2.discourse-cdn.com/free1/user_avatar/iplug2.discourse.group/olilarkin/32/2_2.png) [@olilarkin](https://iplug2.discourse.group/u/olilarkin)\
**Post date:** [17 February 2025 19:33 UTC](https://iplug2.discourse.group/t/plugin-crashes-on-accessing-dropdown-after-closing-and-re-opening-in-bitwig/982/2 "2025-02-17T19:33:24Z")

</div>

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

> <https://github.com/iPlug2/iPlug2/blob/master/Examples/IPlugControls/IPlugControls.cpp#L11C1-L12C1>

> <https://github.com/iPlug2/iPlug2/blob/master/Examples/IPlugControls/IPlugControls.cpp#L117>

> <https://github.com/iPlug2/iPlug2/blob/master/Examples/IPlugControls/IPlugControls.cpp#L195C1-L196C1>

for example

---

<div class="post-metadata">

**Author:** ![walmik](https://yyz2.discourse-cdn.com/free1/user_avatar/iplug2.discourse.group/walmik/32/393_2.png) [@walmik](https://iplug2.discourse.group/u/walmik)\
**Post date:** [18 February 2025 19:37 UTC](https://iplug2.discourse.group/t/plugin-crashes-on-accessing-dropdown-after-closing-and-re-opening-in-bitwig/982/3 "2025-02-18T19:37:55Z")

</div>

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)
