Cocoa: Crash in _NSDisplayOperationStack; Need Guidance

夙愿已清 提交于 2019-12-10 23:23:08

问题


The Problem

I'm receiving crash reports from users that look like this:


Code Type:       X86-64 (Native)
Parent Process:  launchd [223]

Date/Time:       2012-03-22 11:28:33.087 +0800
OS Version:      Mac OS X 10.7.3 (11D50)
Report Version:  9

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

Exception Type:  EXC_BAD_ACCESS (SIGSEGV)
Exception Codes: 0x000000000000000d, 0x0000000000000000

VM Regions Near 0:
--> 
    __TEXT                 000000010c202000-000000010c29c000 [  616K] r-x/rwx SM=COW      /Applications/CodeKit.app/Contents/MacOS/CodeKit

Application Specific Information:
objc_msgSend() selector name: release
objc[22113]: garbage collection is OFF

Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0   libobjc.A.dylib                 0x00007fff904f5390 objc_msgSend_vtable14 + 16
1   com.apple.Foundation            0x00007fff8f664137 empty + 61
2   com.apple.Foundation            0x00007fff8f666c10 dealloc + 24
3   com.apple.Foundation            0x00007fff8f666bd1 -[NSConcreteMapTable dealloc] + 64
4   com.apple.AppKit                0x00007fff892bc52c -[_NSDisplayOperation dealloc] + 84
5   com.apple.CoreFoundation        0x00007fff8fdc7ca0 CFRelease + 176
6   com.apple.CoreFoundation        0x00007fff8fdf0742 -[__NSArrayM removeObjectAtIndex:]     + 434
7   com.apple.AppKit                0x00007fff892bc408 -[_NSDisplayOperationStack     exitDisplayOperationForWindow:] + 417
8   com.apple.AppKit                0x00007fff892be2fc -[NSView _displayRectIgnoringOpacity:isVisibleRect:rectIsVisibleRectForView:] + 7136
9   com.apple.AppKit                0x00007fff892b6429 -[NSView displayIfNeeded] + 1676
10  [SEE DISCUSSION BELOW]

Discussion

Lines 10 and below vary wildly between reports (and hence are unrelated to the crash). However, the sequence from lines 1 to 9 is always the same. Every crash contains this exact sequence. I've googled "_NSDisplayOperationStack" and I've found similar crash reports for dozens of apps (including well-known ones such as Omni apps and Apple's Motion.)


What I Need

Because the crash is coming from Core Foundation, I have no idea where to begin looking for the problem. It seems to be deep inside Cocoa's private view-drawing machinery. Worse still, I can't replicate the crash on my machine at all, so I can't trace it with Instruments. But I've received many reports with the pattern above, so I know it's a problem. Worse STILL, the users can't even reproduce the crash reliably -- it's completely intermittent.

I'm hoping the above sequence looks familiar to someone and they can give me guidance on where to start looking for the problem. Thank you.


回答1:


I posted this same question over at the Apple Developer forums and one engineer told me that it looked like the stack trace had to do with concurrent view drawing, which is a feature that was introduced in 10.6.

I went through all of my NIB files and found two NSButton instances that were set to draw concurrently --- this was not intentional; I must have checked that box by accident at some point.

I disabled the concurrent drawing for both of them and this crash has magically disappeared.




回答2:


In some cases disabling concurrent drawing for just some buttons doesn't help. I got the same error as the author's ("_NSDisplayOperationStack underflow raised during heart beat."). Lucky there is a master switch in a window that disables all concurrent drawing for one window:

[self.window setAllowsConcurrentViewDrawing:NO];

Also opening the the window via a block executed on the main queue helped:

dispatch_async(dispatch_get_main_queue(), ^{
    if(nil == self.someWindowController) {
        self.someWindowController = [[[SomeWindowController alloc] initWithWindowNibName:@"SomeWindowController"] autorelease];
    }
    [self.someWindowController.window makeKeyAndOrderFront:self];
});

Showing the window from within a block just postpones the execution a little bit but for my application, some additional window opening via menu shortcut, a combination of the two were the only thing working.



来源:https://stackoverflow.com/questions/9818419/cocoa-crash-in-nsdisplayoperationstack-need-guidance

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!