Crash when closing the Plugin while a PopupMenu is open (LUNA / AU)

Hi everyone,

I’m experiencing the following problem: when I close the plugin UI while a PopupMenu (shown via showMenuAsync) is still visible, the plugin crashes.

This happens only in the DAW LUNA, and only when my plugin is loaded as AU. I’m on macOS Sequoia 15.0.1, M1 Pro.

What seems to happen is that the popup menu is deleted too late, after its parent component no longer exists. The host destroys the editor and its components
synchronously when the window closes, but the menu’s deletion is deferred to a later message-loop pass (ModalComponentManager::handleAsyncUpdate
PopupMenuCompletionCallback::modalStateFinished). By the time it runs, the parent component is already destroyed.

This is the backtrace of the crashing thread:

Thread 0 Crashed:: JUCE Message Thread Dispatch queue: com.apple.main-thread
0   PluginTest                   	       0x386ce31f8 std::\__1::default_delete<juce::Component>:::operator()[abi:ne180100](juce::Component*) const + 52 (unique_ptr.h:66)
1   PluginTest                   	       0x386c708a4 std::\__1::unique_ptr<juce::Component, std::\__1::default_delete<juce::Component>>::reset[abi:ne180100](juce::Component*) + 104 (unique_ptr.h:266)
2   PluginTest                   	       0x386e9aa08 juce::PopupMenuCompletionCallback::modalStateFinished(int) + 172 (juce_PopupMenu.cpp:2113)
3   PluginTest                   	       0x386d1798c juce::ModalComponentManager::handleAsyncUpdate() + 276 (juce_ModalComponentManager.cpp:208)
4   PluginTest                   	       0x38744f654 juce::AsyncUpdater::AsyncUpdaterMessage::messageCallback() + 68 (juce_AsyncUpdater.cpp:46)
5   PluginTest                   	       0x38746ca3c juce::MessageQueue::deliverNextMessage() + 112 (juce_MessageQueue_mac.h:93)
6   PluginTest                   	       0x38746c994 juce::MessageQueue::runLoopCallback() + 72 (juce_MessageQueue_mac.h:104)
7   PluginTest                   	       0x38746c6a0 juce::MessageQueue::runLoopSourceCallback(void\*) + 24 (juce_MessageQueue_mac.h:112)
8   CoreFoundation                	       0x197736414 **CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION** + 28
9   CoreFoundation                	       0x1977363a8 \__CFRunLoopDoSource0 + 176
10  CoreFoundation                	       0x19773610c \__CFRunLoopDoSources0 + 244
11  CoreFoundation                	       0x197734cf8 \__CFRunLoopRun + 840
12  CoreFoundation                	       0x197734334 CFRunLoopRunSpecific + 572
13  HIToolbox                     	       0x1a2b6d0cc RunCurrentEventLoopInMode + 292
14  HIToolbox                     	       0x1a2b72ebc ReceiveNextEventCommon + 636
15  HIToolbox                     	       0x1a2b73020 \_BlockUntilNextEventMatchingListInModeWithFilter + 76
16  AppKit                        	       0x19b278a70 \_DPSNextEvent + 660
17  AppKit                        	       0x19bb9e7b8 -\[NSApplication(NSEventRouting) \_nextEventMatchingEventMask:untilDate:inMode:dequeue:\] + 688
18  AppKit                        	       0x19b26bb7c -\[NSApplication run\] + 480
19  Rack                          	       0x301ad78a8 juce::JUCEApplicationBase::main() + 196
20  Rack                          	       0x301ad77c4 juce::JUCEApplicationBase::main(int, char const\*\*) + 96
21  Rack                          	       0x3005df81c Launch_RackApplication + 852
22  LUNA                          	       0x104f6b424 Rack_LauncherApplication::RunMainApplication(int, char\*\*) + 976
23  LUNA                          	       0x104f621bc main + 92
24  dyld                          	       0x1972cc274 start + 2840

My question is: is there a way to make sure an open PopupMenu is fully closed and deleted before all the other components are destroyed?

Thanks!

If you are using modal loops the solution is to not use them

Not experienced this exact issue, but did have something similar happening in a Standalone build of a plugin.

PopupMenu::dismissAllActiveMenus(); at the appropriate place was our solution.

I’m not using any modal loops, the menu is shown with showMenuAsync

Unfortunately, this didn’t solve the issue. I tried calling it from the destructor of the component containing the popup menu and the top-level one.