Hi
I have a problem with async menus and destroy lifecycle for my AudioProcessorEditor. Short version is that in the event you close (destroy) an AudioProcessorEditor with a menu open and that menu has a callback, the menu will be asynchronously called after the AudioProcessorEditor is destroyed, and there is no way with current code to avoid that that I have found (I do find a super gross way below).
Longer explanation:
In my code I do
auto p = juce::PopupMenu();
// build
p.showMenuAsync(options, [this](int) { this->whatever(); }
This requires me to make sure this lasts longer than the menu, which i assiduously do.
But there’s one point where i can’t do this and its a bit odd but it is a real problem.
Imagine I click a button to run that code, so the menu is showing. Now, if I close the UI with the menu open then the callback is called after the destruction happens. Specifically if, say, in Reaper I open the menu then press the “FX” button to close the UI, I get a call to ~AudioProcessorEditor() before the menu callbacks are called.
So I thought “I should call juce::PopupMenu::dismissAllActiveMenus() when I close”. So I do that.
Dissapointingly, I found that juce::PopupMenu::dismissAllActiveMenus() does close the windows but leaves the callbacks still scheduled.
So if I put a print in the destructor of my menu bound object, a print in the menu callback, and a print around dismissAll I get this order
Dismiss All Active Menus
Back from Dismiss
Destroying Oscillator Menu 0x7fecf2b18c70
Calling endHover on 0x7fecf2b18c70
That is obviously not the order I want. I also tried adding a call to juce::ModalComponentManager::getInstance()->cancelAllModalComponents(); but that still didn’t cancel my callbacks. The integer value my callback is passed doesn’t let me differentiate between a cancel and a close. So I’m stuck. Right now if you close surge with a menu open you will get a memory scribble.
So: How do I close an async juce::PopupMenu where i have done a showAsync in my editor destructor so as to not get a crash? Any thoughts welcome.
