BR: MenuBarComponent crash closing window

I got a crash when a MenuBarComponent’s popup is dismissed while closing the owning window.

Process:               PopupCrash [1987]
Path:                  /Users/USER/*/PopupCrash.app/Contents/MacOS/PopupCrash
Identifier:            com.yourcompany.PopupCrash
Version:               1.0.0 (1.0.0)
Code Type:             X86-64 (Native)
Parent Process:        ??? [1]
Responsible:           PopupCrash [1987]
User ID:               501

Date/Time:             2021-11-01 15:37:37.592 +0100
OS Version:            macOS 11.6 (20G165)
Report Version:        12
Anonymous UUID:        B3D9F412-FAF3-CEA2-D879-DDE89B833DF5

Sleep/Wake UUID:       B560560B-F9BA-4251-A1A1-5AAFB72F5670

Time Awake Since Boot: 10000 seconds
Time Since Wake:       2600 seconds

System Integrity Protection: enabled

Crashed Thread:        0  JUCE Message Thread  Dispatch queue: com.apple.main-thread

Exception Type:        EXC_BAD_ACCESS (SIGSEGV)
Exception Codes:       EXC_I386_GPFLT
Exception Note:        EXC_CORPSE_NOTIFY

Termination Signal:    Segmentation fault: 11
Termination Reason:    Namespace SIGNAL, Code 0xb
Terminating Process:   exc handler [1987]

Thread 0 Crashed:: JUCE Message Thread  Dispatch queue: com.apple.main-thread
0   com.yourcompany.PopupCrash    	0x000000010769e7bc juce::WeakReference<juce::Component, juce::ReferenceCountedObject>::SharedPointer::get() const + 12 (juce_WeakReference.h:132)
1   com.yourcompany.PopupCrash    	0x0000000107a9ad89 juce::WeakReference<juce::Component, juce::ReferenceCountedObject>::Master::getSharedPointer(juce::Component*) + 137 (juce_WeakReference.h:173)
2   com.yourcompany.PopupCrash    	0x0000000107a9acd3 juce::WeakReference<juce::Component, juce::ReferenceCountedObject>::getRef(juce::Component*) + 67 (juce_WeakReference.h:207)
3   com.yourcompany.PopupCrash    	0x0000000107a9ac7d juce::WeakReference<juce::Component, juce::ReferenceCountedObject>::WeakReference(juce::Component*) + 29 (juce_WeakReference.h:84)
4   com.yourcompany.PopupCrash    	0x00000001078e421d juce::WeakReference<juce::Component, juce::ReferenceCountedObject>::WeakReference(juce::Component*) + 29 (juce_WeakReference.h:84)
5   com.yourcompany.PopupCrash    	0x00000001078ee3f4 juce::Component::postCommandMessage(int) + 52 (juce_Component.cpp:2327)
6   com.yourcompany.PopupCrash    	0x0000000107971d2a juce::MenuBarComponent::menuDismissed(int, int) + 42 (juce_MenuBarComponent.cpp:255)
7   com.yourcompany.PopupCrash    	0x0000000107affaa1 juce::MenuBarComponent::showMenu(int)::$_67::operator()(int) const + 33 (juce_MenuBarComponent.cpp:247)
8   com.yourcompany.PopupCrash    	0x0000000107affa61 decltype(std::__1::forward<juce::MenuBarComponent::showMenu(int)::$_67&>(fp)(std::__1::forward<int>(fp0))) std::__1::__invoke<juce::MenuBarComponent::showMenu(int)::$_67&, int>(juce::MenuBarComponent::showMenu(int)::$_67&, int&&) + 49 (type_traits:3747)
9   com.yourcompany.PopupCrash    	0x0000000107affa02 void std::__1::__invoke_void_return_wrapper<void>::__call<juce::MenuBarComponent::showMenu(int)::$_67&, int>(juce::MenuBarComponent::showMenu(int)::$_67&, int&&) + 50 (__functional_base:348)
10  com.yourcompany.PopupCrash    	0x0000000107aff9c2 std::__1::__function::__alloc_func<juce::MenuBarComponent::showMenu(int)::$_67, std::__1::allocator<juce::MenuBarComponent::showMenu(int)::$_67>, void (int)>::operator()(int&&) + 50 (functional:1553)
11  com.yourcompany.PopupCrash    	0x0000000107afe703 std::__1::__function::__func<juce::MenuBarComponent::showMenu(int)::$_67, std::__1::allocator<juce::MenuBarComponent::showMenu(int)::$_67>, void (int)>::operator()(int&&) + 51 (functional:1727)
12  com.yourcompany.PopupCrash    	0x0000000107b09dcd std::__1::__function::__value_func<void (int)>::operator()(int&&) const + 77 (functional:1880)
13  com.yourcompany.PopupCrash    	0x0000000107b09d2f std::__1::function<void (int)>::operator()(int) const + 47 (functional:2555)
14  com.yourcompany.PopupCrash    	0x0000000107b09cac void juce::NullCheckedInvocation::invoke<void (int), int&>(std::__1::function<void (int)>&&, int&) + 76 (juce_Functional.h:40)
15  com.yourcompany.PopupCrash    	0x0000000107b09aed juce::ModalComponentManager::Callback* juce::ModalCallbackFunction::create<std::__1::function<void (int)>&>(std::__1::function<void (int)>&)::Callable::modalStateFinished(int) + 45 (juce_ModalComponentManager.h:179)
16  com.yourcompany.PopupCrash    	0x00000001078fbb11 juce::ModalComponentManager::handleAsyncUpdate() + 273 (juce_ModalComponentManager.cpp:210)
17  com.yourcompany.PopupCrash    	0x00000001077ba50b juce::AsyncUpdater::AsyncUpdaterMessage::messageCallback() + 75 (juce_AsyncUpdater.cpp:34)
18  com.yourcompany.PopupCrash    	0x00000001077c3da3 juce::MessageQueue::deliverNextMessage() + 99 (juce_osx_MessageQueue.h:81)
19  com.yourcompany.PopupCrash    	0x00000001077c3cf6 juce::MessageQueue::runLoopCallback() + 54 (juce_osx_MessageQueue.h:92)
20  com.yourcompany.PopupCrash    	0x00000001077c39e8 juce::MessageQueue::runLoopSourceCallback(void*) + 24 (juce_osx_MessageQueue.h:100)
21  com.apple.CoreFoundation      	0x00007fff204e92bc __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
22  com.apple.CoreFoundation      	0x00007fff204e9224 __CFRunLoopDoSource0 + 180
23  com.apple.CoreFoundation      	0x00007fff204e8fa4 __CFRunLoopDoSources0 + 242
24  com.apple.CoreFoundation      	0x00007fff204e79cc __CFRunLoopRun + 893
25  com.apple.CoreFoundation      	0x00007fff204e6f8c CFRunLoopRunSpecific + 563
26  com.apple.HIToolbox           	0x00007fff2872f1f3 RunCurrentEventLoopInMode + 292
27  com.apple.HIToolbox           	0x00007fff2872ee26 ReceiveNextEventCommon + 284
28  com.apple.HIToolbox           	0x00007fff2872ecf3 _BlockUntilNextEventMatchingListInModeWithFilter + 70
29  com.apple.AppKit              	0x00007fff22cf0172 _DPSNextEvent + 864
30  com.apple.AppKit              	0x00007fff22cee945 -[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 1364
31  com.apple.AppKit              	0x00007fff22ce0c69 -[NSApplication run] + 586
32  com.yourcompany.PopupCrash    	0x00000001077ad495 juce::MessageManager::runDispatchLoop() + 165 (juce_mac_MessageManager.mm:359)
33  com.yourcompany.PopupCrash    	0x00000001077ad36b juce::JUCEApplicationBase::main() + 379 (juce_ApplicationBase.cpp:262)
34  com.yourcompany.PopupCrash    	0x00000001077ad18c juce::JUCEApplicationBase::main(int, char const**) + 60 (juce_ApplicationBase.cpp:240)
35  com.yourcompany.PopupCrash    	0x000000010769c633 main + 51 (Main.cpp:4)
36  libdyld.dylib                 	0x00007fff2040cf3d start + 1

Thread 1:
0   libsystem_pthread.dylib       	0x00007fff203ed420 start_wqthread + 0

Thread 2:
0   libsystem_pthread.dylib       	0x00007fff203ed420 start_wqthread + 0

Thread 3:
0   libsystem_pthread.dylib       	0x00007fff203ed420 start_wqthread + 0

Thread 4:
0   libsystem_pthread.dylib       	0x00007fff203ed420 start_wqthread + 0

Thread 5:: JUCE Timer
0   libsystem_kernel.dylib        	0x00007fff203becde __psynch_cvwait + 10
1   libsystem_pthread.dylib       	0x00007fff203f1e49 _pthread_cond_wait + 1298
2   libc++.1.dylib                	0x00007fff2035ae03 std::__1::condition_variable::__do_timed_wait(std::__1::unique_lock<std::__1::mutex>&, std::__1::chrono::time_point<std::__1::chrono::system_clock, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1000000000l> > >) + 93
3   com.yourcompany.PopupCrash    	0x00000001077578f6 std::__1::cv_status std::__1::condition_variable::wait_for<long long, std::__1::ratio<1l, 1000000000l> >(std::__1::unique_lock<std::__1::mutex>&, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1000000000l> > const&) + 358 (__mutex_base:468)
4   com.yourcompany.PopupCrash    	0x00000001077575cc void std::__1::condition_variable::__do_timed_wait<std::__1::chrono::steady_clock>(std::__1::unique_lock<std::__1::mutex>&, std::__1::chrono::time_point<std::__1::chrono::steady_clock, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1000000000l> > >) + 92 (__mutex_base:523)
5   com.yourcompany.PopupCrash    	0x000000010775736b std::__1::cv_status std::__1::condition_variable::wait_until<std::__1::chrono::steady_clock, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1000000000l> > >(std::__1::unique_lock<std::__1::mutex>&, std::__1::chrono::time_point<std::__1::chrono::steady_clock, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1000000000l> > > const&) + 139 (__mutex_base:426)
6   com.yourcompany.PopupCrash    	0x0000000107789f49 bool std::__1::condition_variable::wait_until<std::__1::chrono::steady_clock, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1000000000l> >, juce::WaitableEvent::wait(int) const::$_15>(std::__1::unique_lock<std::__1::mutex>&, std::__1::chrono::time_point<std::__1::chrono::steady_clock, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1000000000l> > > const&, juce::WaitableEvent::wait(int) const::$_15) + 73 (__mutex_base:438)
7   com.yourcompany.PopupCrash    	0x0000000107711887 bool std::__1::condition_variable::wait_for<long long, std::__1::ratio<1l, 1000l>, juce::WaitableEvent::wait(int) const::$_15>(std::__1::unique_lock<std::__1::mutex>&, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1000l> > const&, juce::WaitableEvent::wait(int) const::$_15) + 103 (__mutex_base:482)
8   com.yourcompany.PopupCrash    	0x00000001076e07df juce::WaitableEvent::wait(int) const + 207 (juce_WaitableEvent.cpp:43)
9   com.yourcompany.PopupCrash    	0x00000001076e2a44 juce::Thread::wait(int) const + 36 (juce_Thread.cpp:301)
10  com.yourcompany.PopupCrash    	0x00000001077bb755 juce::Timer::TimerThread::run() + 437 (juce_Timer.cpp:88)
11  com.yourcompany.PopupCrash    	0x00000001076e1884 juce::Thread::threadEntryPoint() + 372 (juce_Thread.cpp:96)
12  com.yourcompany.PopupCrash    	0x00000001076e1d58 juce::juce_threadEntryPoint(void*) + 24 (juce_Thread.cpp:118)
13  com.yourcompany.PopupCrash    	0x000000010770cdd9 juce::threadEntryProc(void*) + 41 (juce_posix_SharedCode.h:859)
14  libsystem_pthread.dylib       	0x00007fff203f18fc _pthread_start + 224
15  libsystem_pthread.dylib       	0x00007fff203ed443 thread_start + 15

Thread 6:: com.apple.NSEventThread
0   libsystem_kernel.dylib        	0x00007fff203bc2ba mach_msg_trap + 10
1   libsystem_kernel.dylib        	0x00007fff203bc62c mach_msg + 60
2   com.apple.CoreFoundation      	0x00007fff204e949f __CFRunLoopServiceMachPort + 316
3   com.apple.CoreFoundation      	0x00007fff204e7b7f __CFRunLoopRun + 1328
4   com.apple.CoreFoundation      	0x00007fff204e6f8c CFRunLoopRunSpecific + 563
5   com.apple.AppKit              	0x00007fff22e7623a _NSEventThread + 124
6   libsystem_pthread.dylib       	0x00007fff203f18fc _pthread_start + 224
7   libsystem_pthread.dylib       	0x00007fff203ed443 thread_start + 15

Thread 0 crashed with X86 Thread State (64-bit):
  rax: 0x0065007000700061  rbx: 0x0000600000ba5500  rcx: 0x0000000000000000  rdx: 0x00007ff6e8d29ca8
  rdi: 0x0065007000700061  rsi: 0x0000000000000000  rbp: 0x00007ffee8572fc0  rsp: 0x00007ffee8572fc0
   r8: 0x0000000000000000   r9: 0x00007ffee85730b0  r10: 0x0000600000ca9b00  r11: 0x00007fff22d3b26e
  r12: 0x00000001077c39d0  r13: 0x0000093c13f17203  r14: 0x00006000015a4770  r15: 0x0000000000000000
  rip: 0x000000010769e7bc  rfl: 0x0000000000010206  cr2: 0xffffffa04d8d8000
  
Logical CPU:     2
Error Code:      0x00000000
Trap Number:     13

Thread 0 instruction stream:
  4f 00 be 8a 01 00 00 e8-58 47 00 00 e8 e3 48 00  O.......XG....H.
  00 a8 01 0f 85 05 00 00-00 e9 01 00 00 00 cc e8  ................
  90 01 ff ff e9 00 00 00-00 e9 00 00 00 00 e9 00  ................
  00 00 00 e9 00 00 00 00-48 8b 45 f0 48 8b 00 48  ........H.E.H..H
  83 c4 10 5d c3 66 2e 0f-1f 84 00 00 00 00 00 0f  ...].f..........
  1f 44 00 00 55 48 89 e5-48 89 7d f8 48 8b 45 f8  .D..UH..H.}.H.E.
 [48]8b 40 10 5d c3 66 2e-0f 1f 84 00 00 00 00 00  H.@.].f.........	<==
  0f 1f 40 00 55 48 89 e5-48 83 ec 20 48 89 7d f8  ..@.UH..H.. H.}.
  48 8b 7d f8 48 c7 45 f0-00 00 00 00 48 8d 75 f0  H.}.H.E.....H.u.
  48 8d 55 e8 e8 1b 00 00-00 e9 00 00 00 00 48 83  H.U...........H.
  c4 20 5d c3 48 89 c7 48-89 55 e0 e8 44 fc fe ff  . ].H..H.U..D...
  0f 1f 40 00 55 48 89 e5-48 83 ec 20 48 89 7d f8  ..@.UH..H.. H.}.
  
Thread 0 last branch register state not available.

Called with already deleted function
how are you creating the menu? are you forgetting to delete a pointer in the destructor?

1 Like

Notice that this error message is mine. :grinning_face_with_smiling_eyes:

void drawPopupMenuBackgroundWithOptions (juce::Graphics& g,
    int width,
    int height,
    const juce::PopupMenu::Options& options) override
{
    juce::Component *c = options.getTargetComponent();
    const bool isBox = (dynamic_cast<juce::ComboBox*> (c) != nullptr);
    const bool isBar = (dynamic_cast<juce::MenuBarComponent*> (c) != nullptr);
    
    if (isBox) {
        g.fillAll (juce::Colours::green);
    } else if (isBar) {
        g.fillAll (juce::Colours::blue);
    } else {
        g.fillAll (juce::Colours::red);     DBG ("Called with already deleted component!");
    }
}

I’ll extra check today, but i don’t think i’m doing something wrong. Isn’t it?

Thanks for reporting. When the menu is dismissed it calls a lambda that captures the menu bar component. It looks like this lambda just needs to add a check that the menu still exists before trying to use it. I’ll make that change shortly and update this thread once the change is on develop.

1 Like

Thanks for your patience. I think this commit should resolve the issue:

Please update, and let us know if you run into any further problems.

1 Like