1

更新:在 Sierra 10.12.6 上不会发生崩溃。但它确实每次都出现在我的 High Sierra 10.13.4 机器上。所以这似乎是在 High Sierra 中某个时候引入的 AppKit 问题。记录了 Apple 的错误。


我在这里创建了一个最小的示例。

NSWindowController的负载NSWindow来自 .xib 文件。该窗口仅包含一个NSScrollView. 在awakeFromNib中,我将滚动视图文档设置为我的NSOpenGLView子类的一个实例:

- (void)awakeFromNib
{
    sessionView = [[SessionView alloc] initWithFrame:NSMakeRect(0, 0, 1024, 768) pixelFormat:[NSOpenGLView defaultPixelFormat]];
    [self.sessionScrollView setDocumentView:sessionView];
}

NSOpenGLView子类可以是完全空的实现,例如:

标题

#import <Cocoa/Cocoa.h>
#import <OpenGL/gl.h>

@interface SessionView : NSOpenGLView
{

}

@end

实施

#import "SessionView.h"

@implementation SessionView

@end

现在抓住窗口的一角并开始调整大小。将手指放在鼠标按钮上,拖动窗口边缘直到崩溃。

手表

*** 由于未捕获的异常“NSInternalInconsistencyException”而终止应用程序,原因:“不平衡需要在 rect 发布计数中显示。”

(我把完整的堆栈跟踪放在帖子的末尾,你会看到它都是框架代码)。

所以这些方法_enableNeedsDisplayInRectNotifications_enableNeedsDisplayInRectNotifications. 让我们覆盖它们:

static int count;

- (void)_enableNeedsDisplayInRectNotifications
{
    count--;

    NSLog(@"enable");
    [super _enableNeedsDisplayInRectNotifications];
}

- (void)_disableNeedsDisplayInRectNotifications
{
    count++;

    NSLog(@"disable");
    [super _disableNeedsDisplayInRectNotifications];
}

我们可以看到,当我们调整窗口大小时,_enableNeedsDisplayInRectNotifications会重复调用。一旦我们松开鼠标并结束调整大小,_disableNeedsDisplayInRectNotifications每次调用都会调用一次_enable...

问题是,如果我们的计数达到 -63;我们崩溃了。

我可以通过覆盖这些方法而不是调用super.

到底是怎么回事?

完整的堆栈跟踪:

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 test2 0x000000010949ffb3 -[SessionView _disableNeedsDisplayInRectNotifications] + 83 6 AppKit 0x00007fff4e06876b] + [_NSPortalView72 setSourceView:
0x00007fff4e06802a -[NSPortalView dealloc] + 89 8 libobjc.A.dylib
0x00007fff77b49087 _ZN12_GLOBAL__N_119AutoreleasePoolPage3popEPv + 817 9 CoreFoundation 0x00007fff50412a56 _CFAutoreleasePoolPop + 22 10 Foundation 0x00007fff525378ad -[NSAutoreleasePool drain] + 144 11 AppKit
0x00007fff4d9e3990 -[NSApplication run] + 1031 12 AppKit
0x00007fff4d9b2a72 NSApplicationMain + 804 13 test2
0x000000010949ffe2 主要 + 34 14 libdyld.dylib
0x00007fff7876d015 开始 + 1 15 ???
0x0000000000000001 0x0 + 1

Thread 0 Crashed:: Dispatch queue: com.apple.main-thread 0
libsystem_kernel.dylib 0x00007fff788bdb6e __pthread_kill + 10 1 libsystem_pthread.dylib 0x00007fff78a88080 pthread_kill + 333 2 libsystem_c.dylib 0x00007fff788191ae abort + 127 3 libc++abi.dylib 0x00007fff7671df8f abort_message + 245 4 libc++abi.dylib 0x00007fff7671e12b default_terminate_handler() + 265 5 libobjc.A.dylib
0x00007fff77b55ea3 _objc_terminate() + 97 6 libc++abi.dylib
0x00007fff767397c9 std::__terminate(void ( )()) + 8
libc++abi.dylib 0x00007fff7673926f __cxa_throw + 121 8 libobjc.A.dylib 0x00007fff77b53da5 objc_exception_throw + 351 9 com.apple.CoreFoundation 0x00007fff504df0c2 +[NSException raise:format:arguments:] + 98 10 com.apple.Foundation 0x00007fff525fb340 -[NSAssertionHandler handleFailureInMethod :object:file:lineNumber:description:] + 193 11 com.apple.AppKit 0x00007fff4e2a9af2 -[NSView(NSInternal) _disableNeedsDisplayInRectNotifications] + 190 12 dev.test2 0x000000010949ffb3 -[SessionView _disableNeedsDisplayInRectNotifications] + 83 (SessionView.m) 131:2 .apple.AppKit 0x00007fff4e06876b -[_NSPortalView2 setSourceView:] + 166 14 com.apple.AppKit
0x00007fff4e06802a -[NSPortalView dealloc] + 89 15 libobjc.A.dylib
0x00007fff77b49087 (anonymous namespace)::AutoreleasePoolPage::pop(void
) + 817 16 com.apple.CoreFoundation 0x00007fff50412a56 _CFAutoreleasePoolPop + 22 17 com.apple.Foundation 0x00007fff525378ad -[NSAutoreleasePool排水] + 144 18 com.Apple.Appkit 0x00007fff4d9e3990- [NSAPPLICICATION RUN] + 1031 19 COM.APPLE.APPLE.APPKIT 0X00007FFF4D9B2A72 NSAPPLICATION MAIN + 804 20 DEV.TEST2 0X0000000000010949FFE2 MAIN.LIB
+ 34(MAIN.LIB)(MAIN.LIB)(MAIN.LIB)(MAIN.LIB)(4
) 1

4

0 回答 0