NSApplication Assert failure when exiting fullscreen

269 Views Asked by At

I've written a corevideo application which has one window with a single content view.

The window resizes as expected. I've added the code to make it accept the fullscreen event, which the window does and works as expected, the dock and menu autohide and appear when the mouse hovers in the expected places.

However when I come out of fullscreen mode, I get an assertion failure in the AppKit's NSWindow_FullScreen.m which I cannot find mentioned anywhere in the fullscreen documentation nor can I find the error message searching google. I've tried adding an observer for the NSWindowDidExitFullScreen Notification but the assertion remains. I'm hoping someone can help.

2020-05-10 10:01:16.812 a.out[45616:2858300] *** Assertion failure in -[NSWindow _didExitFullScreen], /BuildRoot/Library/Caches/com.apple.xbs/Sources/AppKit/AppKit-1561.61.100/FullScreen.subproj/NSWindow_FullScreen.m:469
2020-05-10 10:01:16.812 a.out[45616:2858300] content controller was not cleaned up properly

I'm not sure what it's referring to as the Content Controller, I've tried adding a window controller but it still fails, I'm not sure what needs to be cleaned up, as my application is still running and rendering in the window.

Here's my minimal app which exhibits the issue. Compile with: gcc -framework AppKit example.m

#import <AppKit/AppKit.h>

int main (int argc, char **argv)
{
    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
    [NSApplication sharedApplication];
    [NSApp setActivationPolicy:NSApplicationActivationPolicyRegular];

    NSUInteger windowStyle =  NSWindowStyleMaskTitled | NSWindowStyleMaskClosable | NSWindowStyleMaskResizable;
    NSRect wr = NSMakeRect(0,0,640,480);

    NSWindow * window = [[NSWindow alloc] initWithContentRect:wr
                                          styleMask:windowStyle
                                          backing:NSBackingStoreBuffered
                                          defer:NO];
    [window autorelease];

    NSWindowCollectionBehavior behavior = [window collectionBehavior];
    behavior |= NSWindowCollectionBehaviorFullScreenPrimary;
    [window setCollectionBehavior:behavior];

    [[NSNotificationCenter defaultCenter] 
        addObserver:NSApp 
        selector:@selector(terminate:) 
        name:NSWindowWillCloseNotification 
        object:nil];

    [window orderFrontRegardless];

    [NSApp run];

    [pool drain];
    return 0;
}
1

There are 1 best solutions below

0
On

The cause of this issue is that a NSWindowWillCloseNotification is sent when the window exits fullscreen, removing the lines:

  [[NSNotificationCenter defaultCenter] 
    addObserver:NSApp 
    selector:@selector(terminate:) 
    name:NSWindowWillCloseNotification 
    object:nil];

And handling quit events differently resolved this issue.