title: Cocoa: Crash in _NSDisplayOperationStack; Need Guidance
body: <h2>The Problem</h2>
  
  <p>I'm receiving crash reports from users that look like this:</p>
  
  <hr>
  
  <pre><code>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:
  --&gt; 
      __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]
  </code></pre>
  
  <hr>
  
  <h2>Discussion</h2>
  
  <p>Lines 10 and below vary wildly between reports (and hence are unrelated to the crash). However, the sequence from lines 1 to 9 is <em>always</em> 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.)</p>
  
  <hr>
  
  <h2>What I Need</h2>
  
  <p>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.</p>
  
  <p>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.</p>