Search code examples
objective-ccocoanspopover

NSPopover Crash


I seem to have a major crashing issue with creating and destroying NSPopover objects. The NSPopover is set to an instance variable. Even with the check to see if the popover is nil and making it nil if it isn't, it still ends in a SIGSEGV. I've been trying to figure this issue out for several hours and haven't come up with anything.

- (void)addMenuIconPopup
{
    MenuPopupViewController *popoverController = [[MenuPopupViewController alloc] init];
    if(menuIconPopover != nil) {
        [self removeMenuIconPopup];
    }
    menuIconPopover = [[NSPopover alloc] init];
    [menuIconPopover setContentViewController:popoverController];
    [menuIconPopover showRelativeToRect:[[statusItem view] frame]
                         ofView:[statusItem view]
                  preferredEdge:NSMinYEdge];
}

- (void)removeMenuIconPopup
{
    if(menuIconPopover != nil) {
        [menuIconPopover close];
        menuIconPopover = nil;
    }
}

Edit: It seems that the NSPopover itself is causing the hang. Here is the relevant part of the process sample (blanked the parts that might be under a NDA).

    2762 Thread_2921859
  2762 thread_start  (in libsystem_c.dylib) + 13  [0x7fff8f0011e1]
    2762 _pthread_start  (in libsystem_c.dylib) + 327  [0x7fff8f0147a2]
      2762 ???  (in variouslibrary.dylib)  load address 0x1000cd000 + 0xb9461  [0x100186461]
        2762 ???  (in variouslibrary.dylib)  load address 0x1000cd000 + 0x26390  [0x1000f3390]
          2762 VariousControllerDelegateListener::onConnect(VariousController::Controller const&)  (in App) + 93  [0x10001d4cd]  VariousControllerObjectiveC.mm:1752
            2762 -[VariousControllerController onConnect:]  (in App) + 126  [0x100006eae]  VariousControllerController.m:215
              2762 -[TutorialWindowController variousControllerConnected]  (in App) + 88  [0x100031a78]  TutorialWindowController.m:93
                2762 _NSPopoverCloseAndAnimate  (in AppKit) + 840  [0x7fff89bac8d7]
                  2762 -[NSWindow orderWindow:relativeTo:]  (in AppKit) + 159  [0x7fff8950ac1f]
                    2762 -[NSWindow _doOrderWindow:relativeTo:findKey:forCounter:force:isModal:]  (in AppKit) + 668  [0x7fff8950af28]
                      2762 -[_NSWindowTransformAnimation startAnimation]  (in AppKit) + 512  [0x7fff8936b95c]
                        2762 _NSWindowExchange  (in AppKit) + 376  [0x7fff89a27555]
                          2762 -[NSWindow _reallyDoOrderWindow:relativeTo:findKey:forCounter:force:isModal:]  (in AppKit) + 1377  [0x7fff8950ba18]
                            2762 -[NSNextStepFrame displayIfNeeded]  (in AppKit) + 84  [0x7fff895d8e64]
                              2762 -[NSView displayIfNeeded]  (in AppKit) + 1044  [0x7fff8944e981]
                                2762 -[NSView _sendViewWillDrawInRect:clipRootView:]  (in AppKit) + 1195  [0x7fff8948240a]
                                  2762 -[NSViewHierarchyLock lockForReadingWithExceptionHandler:]  (in AppKit) + 378  [0x7fff894259e1]
                                    2762 _pthread_cond_wait  (in libsystem_c.dylib) + 869  [0x7fff8f018fe9]
                                      2762 __psynch_cvwait  (in libsystem_kernel.dylib) + 10  [0x7fff8a53d0fa]

Solution

  • I ended up solving the issue by simply calling the function on the main thread, via

        [self performSelectorOnMainThread:@selector(addMenuIconPopup) withObject:(nil) waitUntilDone:NO];