1

在创建和销毁 NSPopover 对象时,我似乎遇到了一个严重的崩溃问题。NSPopover 设置为实例变量。即使检查弹出框是否为 nil,如果不是则使其为零,它仍然以 SIGSEGV 结尾。我一直试图解决这个问题几个小时,但没有提出任何建议。

- (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;
    }
}

编辑: 似乎 NSPopover 本身导致了挂起。这是流程示例的相关部分(将可能在 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]
4

1 回答 1

0

我最终通过简单地调用主线程上的函数来解决这个问题,通过

    [self performSelectorOnMainThread:@selector(addMenuIconPopup) withObject:(nil) waitUntilDone:NO];
于 2013-06-28T01:22:45.900 回答