Fixed assertion when quickly toggling from fullscreen back to fullscreen:
authorSam Lantinga <slouken@libsdl.org>
Mon, 11 Nov 2013 22:43:05 -0800
changeset 7965 d3cbe8ecb1af
parent 7964 56431f7d8f46
child 7966 ef27c2dbeb8f
Fixed assertion when quickly toggling from fullscreen back to fullscreen: "Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'backgroundWindows not nil in enterFullScreenTransitionWithOptions:animated:activatingIt:'" To reproduce this, run testsprite2, press Alt-Enter once, again while it's animating to fullscreen, and then again while it's animating out of fullscreen.
src/video/cocoa/SDL_cocoawindow.m
--- a/src/video/cocoa/SDL_cocoawindow.m	Mon Nov 11 21:38:11 2013 -0800
+++ b/src/video/cocoa/SDL_cocoawindow.m	Mon Nov 11 22:43:05 2013 -0800
@@ -184,10 +184,6 @@
     }
 }
 
--(BOOL) canSetFullscreenState:(BOOL) state;
-{
-}
-
 -(BOOL) setFullscreenState:(BOOL) state;
 {
     SDL_Window *window = _data->window;
@@ -228,7 +224,7 @@
         return YES;
     }
 
-    [nswindow performSelector: @selector(toggleFullScreen:) withObject:nswindow];
+    [nswindow performSelectorOnMainThread: @selector(toggleFullScreen:) withObject:nswindow waitUntilDone:NO];
     return YES;
 }
 
@@ -433,12 +429,15 @@
             [nswindow setStyleMask:NSBorderlessWindowMask];
         }
     }
+
     isFullscreen = YES;
     inFullscreenTransition = YES;
 }
 
 - (void)windowDidEnterFullScreen:(NSNotification *)aNotification
 {
+    SDL_Window *window = _data->window;
+
     inFullscreenTransition = NO;
 
     if (pendingWindowOperation == PENDING_OPERATION_LEAVE_FULLSCREEN) {
@@ -446,6 +445,11 @@
         [self setFullscreenState:NO];
     } else {
         pendingWindowOperation = PENDING_OPERATION_NONE;
+        /* Force the size change event in case it was delivered earlier
+           while the window was still animating into place.
+         */
+        window->w = 0;
+        window->h = 0;
         [self windowDidResize:aNotification];
     }
 }
@@ -465,6 +469,7 @@
 
 - (void)windowDidExitFullScreen:(NSNotification *)aNotification
 {
+    SDL_Window *window = _data->window;
     NSWindow *nswindow = _data->nswindow;
 
     inFullscreenTransition = NO;
@@ -477,6 +482,11 @@
         [nswindow miniaturize:nil];
     } else {
         pendingWindowOperation = PENDING_OPERATION_NONE;
+        /* Force the size change event in case it was delivered earlier
+           while the window was still animating into place.
+         */
+        window->w = 0;
+        window->h = 0;
         [self windowDidResize:aNotification];
     }
 }