Assertion failure in _enableNeedsDisplayInRectNotifications

Hello


My system is Xcode 9.3, High Sierra 10.13.4.


I have an NSWindow containing only a subclass of NSOpenGLView. The view is displaying a simple texture. If I grab the corner of my window and start resizing, after a few seconds dragging the window edge around I get the following crash:


*** Assertion failure in -[MyOpenGLView _enableNeedsDisplayInRectNotifications], /BuildRoot/Library/Caches/com.apple.xbs/Sources/AppKit/AppKit-1561.40.112/AppKit.subproj/NSView.m:18293
[General] Overflowed needs display in rect posting count.


The crash always occurs. If I move the mouse more slowly, it takes a little more time to occur. Move the mouse faster and the crash happens sooner.


I post the full stack trace below. Note that at no point is any of my code listed in the stack. I do not call setNeedsDisplay or setNeedsDisplayInRect: anywhere in response to resizing the window. My gl reshape method is empty. There is no recursion happening in drawRect:.


I can workaround the issue by adding these empty overrides to my view:


- (void)_enableNeedsDisplayInRectNotifications
{ }

- (void)_disableNeedsDisplayInRectNotifications
{ }


It looks and smells like a bug in AppKit. But what is triggering it?


Thanks in advance


Full stack trace:


** Assertion failure in -[MyOpenGLView _enableNeedsDisplayInRectNotifications], /BuildRoot/Library/Caches/com.apple.xbs/Sources/AppKit/AppKit-1561.40.112/AppKit.subproj/NSView.m:18293
2018-04-18 12:08:14.785967-0700 MyApp[22899:701655] [General] Overflowed needs display in rect posting count.
2018-04-18 12:08:14.790419-0700 MyApp[22899:701655] [General] (
  0   CoreFoundation                      0x00007fff504d932b __exceptionPreprocess + 171
  1   libobjc.A.dylib                     0x00007fff77b53c76 objc_exception_throw + 48
  2   CoreFoundation                      0x00007fff504df0c2 +[NSException raise:format:arguments:] + 98
  3   Foundation                          0x00007fff525fb340 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 193
  4   AppKit                              0x00007fff4e2a9a32 -[NSView(NSInternal) _enableNeedsDisplayInRectNotifications] + 202
  5   AppKit                              0x00007fff4e06829f -[NSPortalView layout] + 361
  6   AppKit                              0x00007fff4e299ad0 _NSViewLayout + 587
  7   AppKit                              0x00007fff4da93eff -[NSView _layoutSubtreeWithOldSize:] + 437
  8   AppKit                              0x00007fff4da94178 -[NSView _layoutSubtreeWithOldSize:] + 1070
  9   AppKit                              0x00007fff4da94178 -[NSView _layoutSubtreeWithOldSize:] + 1070
  10  AppKit                              0x00007fff4da94178 -[NSView _layoutSubtreeWithOldSize:] + 1070
  11  AppKit                              0x00007fff4e2a082c -[NSView _layoutSubtreeIfNeededAndAllowTemporaryEngine:] + 1380
  12  AppKit                              0x00007fff4dab16ef -[NSWindow(NSConstraintBasedLayout) _layoutViewTree] + 163
  13  AppKit                              0x00007fff4da9888a -[NSWindow _setFrame:updateBorderViewSize:] + 1124
  14  AppKit                              0x00007fff4dab0c67 -[NSWindow _oldPlaceWindow:] + 604
  15  AppKit                              0x00007fff4dab021a -[NSWindow _setFrameCommon:display:stashSize:] + 3108
  16  AppKit                              0x00007fff4daaf5e9 -[NSWindow _setFrame:display:allowImplicitAnimation:stashSize:] + 222
  17  AppKit                              0x00007fff4daaf504 -[NSWindow setFrame:display:] + 67
  18  AppKit                              0x00007fff4e4f23e9 -[NSWindow(NSWindowResizing) _resizeSetFrame:withEvent:] + 124
  19  AppKit                              0x00007fff4dd1a37f -[NSWindow(NSWindowResizing) _resizeWithEvent:] + 3060
  20  AppKit                              0x00007fff4e258422 -[NSTitledFrame attemptResizeWithEvent:] + 177
  21  AppKit                              0x00007fff4dc243dd -[NSThemeFrame handleMouseDown:] + 297
  22  AppKit                              0x00007fff4dc24603 -[NSThemeFrame mouseDown:] + 30
  23  AppKit                              0x00007fff4e325d6d -[NSWindow(NSEventRouting) _handleMouseDownEvent:isDelayedEvent:] + 5891
  24  AppKit                              0x00007fff4e3229c4 -[NSWindow(NSEventRouting) _reallySendEvent:isDelayedEvent:] + 2359
  25  AppKit                              0x00007fff4e321c70 -[NSWindow(NSEventRouting) sendEvent:] + 497
  26  AppKit                              0x00007fff4e183236 -[NSApplication(NSEvent) sendEvent:] + 2462
  27  AppKit                              0x00007fff4d9e38b5 -[NSApplication run] + 812
  28  AppKit                              0x00007fff4d9b2a72 NSApplicationMain + 804
  29  MyApp                             0x000000010003208a main + 170
  30  libdyld.dylib                       0x00007fff7876d015 start + 1
  31  ???                                 0x0000000000000001 0x0 + 1
)
2018-04-18 12:08:14.791393-0700 MyApp[22899:701655] *** Assertion failure in -[MyOpenGLView _disableNeedsDisplayInRectNotifications], /BuildRoot/Library/Caches/com.apple.xbs/Sources/AppKit/AppKit-1561.40.112/AppKit.subproj/NSView.m:18297
2018-04-18 12:08:14.792496-0700 MyApp[22899:701655] [General] An uncaught exception was raised
2018-04-18 12:08:14.792513-0700 MyApp[22899:701655] [General] Unbalanced needs display in rect posting count.
2018-04-18 12:08:14.792573-0700 MyApp[22899:701655] [General] (
  0   CoreFoundation                      0x00007fff504d932b __exceptionPreprocess + 171
  1   libobjc.A.dylib                     0x00007fff77b53c76 objc_exception_throw + 48
  2   CoreFoundation                      0x00007fff504df0c2 +[NSException raise:format:arguments:] + 98
  3   Foundation                          0x00007fff525fb340 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 193
  4   AppKit                              0x00007fff4e2a9af2 -[NSView(NSInternal) _disableNeedsDisplayInRectNotifications] + 190
  5   AppKit                              0x00007fff4e06876b -[_NSPortalView2 setSourceView:] + 166
  6   AppKit                              0x00007fff4e06802a -[NSPortalView dealloc] + 89
  7   libobjc.A.dylib                     0x00007fff77b49087 _ZN12_GLOBAL__N_119AutoreleasePoolPage3popEPv + 817
  8   CoreFoundation                      0x00007fff50412a56 _CFAutoreleasePoolPop + 22
  9   Foundation                          0x00007fff525378ad -[NSAutoreleasePool drain] + 144
  10  AppKit                              0x00007fff4d9e3990 -[NSApplication run] + 1031
  11  AppKit                              0x00007fff4d9b2a72 NSApplicationMain + 804
  12  MyApp                             0x000000010003208a main + 170
  13  libdyld.dylib                       0x00007fff7876d015 start + 1
  14  ???                                 0x0000000000000001 0x0 + 1
)
2018-04-18 12:08:14.793037-0700 MyApp[22899:701655] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Unbalanced needs display in rect posting count.'
*** First throw call stack:
(
  0   CoreFoundation                      0x00007fff504d932b __exceptionPreprocess + 171
  1   libobjc.A.dylib                     0x00007fff77b53c76 objc_exception_throw + 48
  2   CoreFoundation                      0x00007fff504df0c2 +[NSException raise:format:arguments:] + 98
  3   Foundation                          0x00007fff525fb340 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 193
  4   AppKit                              0x00007fff4e2a9af2 -[NSView(NSInternal) _disableNeedsDisplayInRectNotifications] + 190
  5   AppKit                              0x00007fff4e06876b -[_NSPortalView2 setSourceView:] + 166
  6   AppKit                              0x00007fff4e06802a -[NSPortalView dealloc] + 89
  7   libobjc.A.dylib                     0x00007fff77b49087 _ZN12_GLOBAL__N_119AutoreleasePoolPage3popEPv + 817
  8   CoreFoundation                      0x00007fff50412a56 _CFAutoreleasePoolPop + 22
  9   Foundation                          0x00007fff525378ad -[NSAutoreleasePool drain] + 144
  10  AppKit                              0x00007fff4d9e3990 -[NSApplication run] + 1031
  11  AppKit                              0x00007fff4d9b2a72 NSApplicationMain + 804
  12  MyApp                             0x000000010003208a main + 170
  13  libdyld.dylib                       0x00007fff7876d015 start + 1
  14  ???                                 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException

Replies

Could you post the code where you draw the content of window ?

rdevo,


Did you ever figure out any solution to your problem?


I'm having a similar issue, but mine is with a NSOutlineView.


I'm running MacOS High Sierra 10.13.6 and Xcode 10.1


I did find a workaround for my issue: If I change my outline view from "Regular" highlight to "Source List", the crash DOES NOT happen. However, with "Source List" as the highlighting type, the outline view changes to a darker background color with a blue highlight rather then my normal system highlight color. I then changed the outline view's background color back to the default control background color, and magically, the highlight color is back to my system highlight color and the source list outline view looks just like a "Regular" outline view — without any exceptions occuring when I resize the window!


I'll post the stack trace from the "Regular" NSOutlineView crash below, just in case it may shed some light on the underlying cause of the exceptions.


2018-12-07 02:20:27.650772-0500 MyApp[89204:16846116] *** Assertion failure in -[NSOutlineView _enableNeedsDisplayInRectNotifications], /BuildRoot/Library/Caches/com.apple.xbs/Sources/AppKit/AppKit-1561.60.100/AppKit.subproj/NSView.m:18293
2018-12-07 02:20:27.655138-0500 MyApp[89204:16846116] [General] Overflowed needs display in rect posting count.
2018-12-07 02:20:27.658245-0500 MyApp[89204:16846116] [General] (
  0   CoreFoundation                      0x00007fff341aa23b __exceptionPreprocess + 171
  1   libobjc.A.dylib                     0x00007fff5b43cc76 objc_exception_throw + 48
  2   CoreFoundation                      0x00007fff341affd2 +[NSException raise:format:arguments:] + 98
  3   Foundation                          0x00007fff362da150 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 193
  4   AppKit                              0x00007fff31f79a32 -[NSView(NSInternal) _enableNeedsDisplayInRectNotifications] + 202
  5   AppKit                              0x00007fff31d3829f -[NSPortalView layout] + 361
  6   AppKit                              0x00007fff31f69ad0 _NSViewLayout + 587
  7   AppKit                              0x00007fff31763eff -[NSView _layoutSubtreeWithOldSize:] + 437
  8   AppKit                              0x00007fff31764178 -[NSView _layoutSubtreeWithOldSize:] + 1070
  9   AppKit                              0x00007fff31764178 -[NSView _layoutSubtreeWithOldSize:] + 1070
  10  AppKit                              0x00007fff31764178 -[NSView _layoutSubtreeWithOldSize:] + 1070
  11  AppKit                              0x00007fff31f7082c -[NSView _layoutSubtreeIfNeededAndAllowTemporaryEngine:] + 1380
  12  AppKit                              0x00007fff317816ef -[NSWindow(NSConstraintBasedLayout) _layoutViewTree] + 163
  13  AppKit                              0x00007fff3176888a -[NSWindow _setFrame:updateBorderViewSize:] + 1124
  14  AppKit                              0x00007fff31780c67 -[NSWindow _oldPlaceWindow:] + 604
  15  AppKit                              0x00007fff3178021a -[NSWindow _setFrameCommon:display:stashSize:] + 3108
  16  AppKit                              0x00007fff3177f5e9 -[NSWindow _setFrame:display:allowImplicitAnimation:stashSize:] + 222
  17  AppKit                              0x00007fff3177f504 -[NSWindow setFrame:display:] + 67
  18  AppKit                              0x00007fff321c23e9 -[NSWindow(NSWindowResizing) _resizeSetFrame:withEvent:] + 124
  19  AppKit                              0x00007fff319ea37f -[NSWindow(NSWindowResizing) _resizeWithEvent:] + 3060
  20  AppKit                              0x00007fff31f28422 -[NSTitledFrame attemptResizeWithEvent:] + 177
  21  AppKit                              0x00007fff318f43dd -[NSThemeFrame handleMouseDown:] + 297
  22  AppKit                              0x00007fff318f4603 -[NSThemeFrame mouseDown:] + 30
  23  AppKit                              0x00007fff31ff5d6d -[NSWindow(NSEventRouting) _handleMouseDownEvent:isDelayedEvent:] + 5891
  24  AppKit                              0x00007fff31ff29c4 -[NSWindow(NSEventRouting) _reallySendEvent:isDelayedEvent:] + 2359
  25  AppKit                              0x00007fff31ff1c70 -[NSWindow(NSEventRouting) sendEvent:] + 497
  26  AppKit                              0x00007fff31e53236 -[NSApplication(NSEvent) sendEvent:] + 2462
  27  AppKit                              0x00007fff316b38b5 -[NSApplication run] + 812
  28  AppKit                              0x00007fff31682a72 NSApplicationMain + 804
  29  MyApp                               0x000000010002c62d main + 13
  30  libdyld.dylib                       0x00007fff5c056015 start + 1
  31  ???                                 0x0000000000000003 0x0 + 3
)
2018-12-07 02:20:27.685109-0500 MyApp[89204:16846116] *** Assertion failure in -[NSOutlineView _disableNeedsDisplayInRectNotifications], /BuildRoot/Library/Caches/com.apple.xbs/Sources/AppKit/AppKit-1561.60.100/AppKit.subproj/NSView.m:18297
2018-12-07 02:20:27.685978-0500 MyApp[89204:16846116] [General] An uncaught exception was raised
2018-12-07 02:20:27.685997-0500 MyApp[89204:16846116] [General] Unbalanced needs display in rect posting count.
2018-12-07 02:20:27.686042-0500 MyApp[89204:16846116] [General] (
  0   CoreFoundation                      0x00007fff341aa23b __exceptionPreprocess + 171
  1   libobjc.A.dylib                     0x00007fff5b43cc76 objc_exception_throw + 48
  2   CoreFoundation                      0x00007fff341affd2 +[NSException raise:format:arguments:] + 98
  3   Foundation                          0x00007fff362da150 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 193
  4   AppKit                              0x00007fff31f79af2 -[NSView(NSInternal) _disableNeedsDisplayInRectNotifications] + 190
  5   AppKit                              0x00007fff31d3876b -[_NSPortalView2 setSourceView:] + 166
  6   AppKit                              0x00007fff31d3802a -[NSPortalView dealloc] + 89
  7   libobjc.A.dylib                     0x00007fff5b432087 _ZN12_GLOBAL__N_119AutoreleasePoolPage3popEPv + 817
  8   CoreFoundation                      0x00007fff340e3926 _CFAutoreleasePoolPop + 22
  9   Foundation                          0x00007fff362167fd -[NSAutoreleasePool drain] + 144
  10  AppKit                              0x00007fff316b3990 -[NSApplication run] + 1031
  11  AppKit                              0x00007fff31682a72 NSApplicationMain + 804
  12  MyApp                               0x000000010002c62d main + 13
  13  libdyld.dylib                       0x00007fff5c056015 start + 1
  14  ???                                 0x0000000000000003 0x0 + 3
)
2018-12-07 02:20:27.686448-0500 MyApp[89204:16846116] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Unbalanced needs display in rect posting count.'
*** First throw call stack:
(
  0   CoreFoundation                      0x00007fff341aa23b __exceptionPreprocess + 171
  1   libobjc.A.dylib                     0x00007fff5b43cc76 objc_exception_throw + 48
  2   CoreFoundation                      0x00007fff341affd2 +[NSException raise:format:arguments:] + 98
  3   Foundation                          0x00007fff362da150 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 193
  4   AppKit                              0x00007fff31f79af2 -[NSView(NSInternal) _disableNeedsDisplayInRectNotifications] + 190
  5   AppKit                              0x00007fff31d3876b -[_NSPortalView2 setSourceView:] + 166
  6   AppKit                              0x00007fff31d3802a -[NSPortalView dealloc] + 89
  7   libobjc.A.dylib                     0x00007fff5b432087 _ZN12_GLOBAL__N_119AutoreleasePoolPage3popEPv + 817
  8   CoreFoundation                      0x00007fff340e3926 _CFAutoreleasePoolPop + 22
  9   Foundation                          0x00007fff362167fd -[NSAutoreleasePool drain] + 144
  10  AppKit                              0x00007fff316b3990 -[NSApplication run] + 1031
  11  AppKit                              0x00007fff31682a72 NSApplicationMain + 804
  12  MyApp                               0x000000010002c62d main + 13
  13  libdyld.dylib                       0x00007fff5c056015 start + 1
  14  ???                                 0x0000000000000003 0x0 + 3
)
libc++abi.dylib: terminating with uncaught exception of type NSException

Could you post the code where the crash occurs ?

@mditsler I had a similar issue of my app crashing when resizing a view that contains a tableview.

Thanks to your story, I figured out my app at least will not crash when setting the table view highlight to "source list". If I change it to anything else than that, then my app will crash when the user resizes the window containing the view. Very frustrating.

This happened to me in Xcode 10.1 on High Sierra.

I will test later what happens when I convert this to Xcode 11.x on Catalina.