Objective c 翻车事故

Objective c 翻车事故,objective-c,cocoa,nspopover,Objective C,Cocoa,Nspopover,我似乎在创建和销毁NSPopover对象时遇到了一个严重的崩溃问题。NSPopover设置为实例变量。即使检查爆米花是否为零,如果不是,则将其设为零,它仍然以SIGSEGV结束。我已经试着解决这个问题好几个小时了,但什么都没想到 - (void)addMenuIconPopup { MenuPopupViewController *popoverController = [[MenuPopupViewController alloc] init]; if(menuIconPopo

我似乎在创建和销毁NSPopover对象时遇到了一个严重的崩溃问题。NSPopover设置为实例变量。即使检查爆米花是否为零,如果不是,则将其设为零,它仍然以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本身导致了挂起。以下是工艺样品的相关部分,包括可能属于保密协议的部分

    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]

我通过在主线程上调用函数via来解决这个问题

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

为什么您很难准确地说出是什么操作导致应用程序崩溃,并显示什么错误消息,除非被询问?确切地说,哪一行给出了SIGSEGV?问题可能不是nil指针,而是引用坏内存的指针。它可能指向已发布的对象。如何使用异常断点查找特定行?它只是向我展示了发生异常的线程,我还不习惯Xcode。该应用程序通常也不会崩溃并生成SIGSEGV报告。取而代之的是,它将只是停留在那里,但永远不会真正终止。