NenpenGLView子类在_enableNeedsDisplayInRectNotifications

时间:2018-04-19 17:54:24

标签: macos cocoa nsview appkit nsopenglview

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

我创建了一个最小的例子here

我的NSWindowController从.xib文件加载NSWindow。该窗口仅包含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

Imlementation

#import "SessionView.h"

@implementation SessionView

@end

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

Watch

  

***由于未捕获的异常终止应用程序&#39; NSInternalInconsistencyException&#39;,原因:&#39;不平衡的需求显示   在直接发布计数。&#39;

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

这些方法_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
  基金会0x00007fff525fb340    - [NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 193 4
  AppKit 0x00007fff4e2a9af2    - [NSView(NSInternal)_disableNeedsDisplayInRectNotifications] + 190 5 test2 0x000000010949ffb3 - [SessionView   _disableNeedsDisplayInRectNotifications] + 83 6 AppKit 0x00007fff4e06876b - [_ NSPortalView2 setSourceView:] + 166 7 AppKit
  0x00007fff4e06802a - [NSPortalView dealloc] + 89 8 libobjc.A.dylib
  0x00007fff77b49087 _ZN12_GLOBAL__N_119AutoreleasePoolPage3popEPv + 817   9 CoreFoundation 0x00007fff50412a56   _CFAutoreleasePoolPop + 22 10基础0x00007fff525378ad - [NSAutoreleasePool drain] + 144 11 AppKit
  0x00007fff4d9e3990 - [NSApplication run] + 1031 12 AppKit
  0x00007fff4d9b2a72 NSApplicationMain + 804 13 test2
  0x000000010949ffe2 main + 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 7
  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:21)13 com.apple.AppKit 0x00007fff4e06876b - [_ NSPortalView2   setSourceView:] + 166 14 com.apple.AppKit
    0x00007fff4e06802a - [NSPortalView dealloc] + 89 15 libobjc.A.dylib
    0x00007fff77b49087(匿名   namespace):: AutoreleasePoolPage :: pop(void
)+ 817 16   com.apple.CoreFoundation 0x00007fff50412a56   _CFAutoreleasePoolPop + 22 17 com.apple.Foundation 0x00007fff525378ad - [NSAutoreleasePool drain] + 144 18   com.apple.AppKit 0x00007fff4d9e3990 - [NSApplication run]   + 1031 19 com.apple.AppKit 0x00007fff4d9b2a72 NSApplicationMain + 804 20 dev.test2
    0x000000010949ffe2 main + 34(main.m:4)21 libdyld.dylib
    0x00007fff7876d015 start + 1

0 个答案:

没有答案
相关问题