Popup menu showMenuAsync() not working in Mac Standalone plugin

I’m working on a plugin that has 3 buttons which each launch a popup menu. As recommended, I am using showMenuAsync because it is a plugin, and this works perfectly fine in Windows but seems to glitch when I run the mac standalone plugin. When I click the button to launch the menu the menu flashes for a moment and then disappears. When I switch the code to use menu.show(), it opens correctly so I believe that this must be an issue with the JUCE code and not something I can fix. Interestingly enough, if I first click button 1 which executes menu.show() and then I click on button 2 which uses showMenuAsync(), then it does work. However once I click on another area of the UI button 2 resumes the glitchy behaviour. In the meantime I will return to using menu.show() for the mac version but hopefully someone could address this issue soon. Thank you!

Can you post some code that reproduces the issue? Are you perhaps creating the PopupMenu on the stack before calling showAsync() and it then goes out of scope?

Thanks for the quick reply Ed! Here is an example of a menu I create.

PopupMenu menu;

menu.addItem(1, “Item1”);
menu.addItem(2, “Item2”);
menu.showMenuAsync(PopupMenu::Options(), [this](int action)
if (action == 1)

else if (action == 2)


Right, but the question is where is that code called from? If, for example, you do something like this:

void mouseUp (const MouseEvent& e) override
    PopupMenu menu;

Then menu goes out of scope immediately after the showMenuAsync() call and will be destroyed, whereas calling show() will block until the menu is dismissed.

isn’t showMenuAsync() designed that way that this should work even when PopupMenu is a stack object, i use that all the time and it works.

1 Like

Oops, yes you’re right. Ignore my previous post.

I have popup menus are in a few different places, but none are working. One is called from mouseDoubleClick(), but others are called from buttonClicked(), and cellClicked().

Can you put a breakpoint in PopupMenu::MenuWindow::hide() (here) and see what’s causing it to be hidden?

It looks like it stems from calling grabKeyboardFocus() which I do at the end of the buttonClicked(). Here is the stack trace from buttonClicked().

#0 0x00000001006b9928 in juce::PopupMenu::HelperClasses::MenuWindow::hide(juce::PopupMenu::Item const*, bool) at /Applications/JUCE/modules/juce_gui_basics/menus/juce_PopupMenu.cpp:303
#1 0x00000001006175fa in juce::PopupMenu::HelperClasses::MenuWindow::dismissMenu(juce::PopupMenu::Item const*) at /Applications/JUCE/modules/juce_gui_basics/menus/juce_PopupMenu.cpp:359
#2 0x0000000100681b14 in juce::PopupMenu::HelperClasses::MenuWindow::inputAttemptWhenModal() at /Applications/JUCE/modules/juce_gui_basics/menus/juce_PopupMenu.cpp:457
#3 0x000000010071f06a in juce::NSViewComponentPeer::sendModalInputAttemptIfBlocked() at /Applications/JUCE/modules/juce_gui_basics/native/juce_mac_NSViewComponentPeer.mm:1008
#4 0x000000010071e005 in juce::JuceNSWindowClass::canBecomeMainWindow(objc_object*, objc_selector*) at /Applications/JUCE/modules/juce_gui_basics/native/juce_mac_NSViewComponentPeer.mm:2000
#5 0x00007fff2cff9997 in -[NSWindow _changeKeyAndMainLimitedOK:] ()
#6 0x00000001007239e7 in juce::NSViewComponentPeer::grabFocus() at /Applications/JUCE/modules/juce_gui_basics/native/juce_mac_NSViewComponentPeer.mm:1388
#7 0x000000010057a8d4 in juce::Component::takeKeyboardFocus(juce::Component::FocusChangeType) at /Applications/JUCE/modules/juce_gui_basics/components/juce_Component.cpp:2720
#8 0x000000010057792e in juce::Component::grabFocusInternal(juce::Component::FocusChangeType, bool) at /Applications/JUCE/modules/juce_gui_basics/components/juce_Component.cpp:2747
#9 0x000000010056b4ec in juce::Component::grabKeyboardFocus() at /Applications/JUCE/modules/juce_gui_basics/components/juce_Component.cpp:2790
#10 0x000000010002fc61 in AudioProcessorEditor::buttonClicked(juce::Button*) at /Users/Project/Code/Source/PluginEditor.cpp:836

What are you calling grabKeyboardFocus() on? If the menu is shown and then loses focus immediately because you are grabbing the focus on a different component then it will dismiss the menu.

Yes that is my mistake, I was calling grabKeyboardFocus() on the main component which would of course hide any visible popup menu… Thanks for helping me figure it all out!

1 Like

Hi @ed95, I’m noticing one other issue with showMenuAsync() that I was hoping you could advise on. I have a button that launches the menu asynchronously and if I click somewhere else on the plugin, the menu disappears as you would expect. However, if I click elsewhere on the DAW (not on the plugin though), the popup menu does not hide which in my opinion is not expected behavior. I would like it to behave in such a way that a click anywhere else on the screen whether it is on the plugin itself or somewhere else on the DAW, will trigger the menu to hide itself. Do you have any ideas on how I can achieve this?