Fixed assertion when quickly toggling from fullscreen back to fullscreen:
authorSam Lantinga <slouken@libsdl.org>
Mon, 11 Nov 2013 22:43:05 -0800
changeset 7965d3cbe8ecb1af
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
     1.1 --- a/src/video/cocoa/SDL_cocoawindow.m	Mon Nov 11 21:38:11 2013 -0800
     1.2 +++ b/src/video/cocoa/SDL_cocoawindow.m	Mon Nov 11 22:43:05 2013 -0800
     1.3 @@ -184,10 +184,6 @@
     1.4      }
     1.5  }
     1.6  
     1.7 --(BOOL) canSetFullscreenState:(BOOL) state;
     1.8 -{
     1.9 -}
    1.10 -
    1.11  -(BOOL) setFullscreenState:(BOOL) state;
    1.12  {
    1.13      SDL_Window *window = _data->window;
    1.14 @@ -228,7 +224,7 @@
    1.15          return YES;
    1.16      }
    1.17  
    1.18 -    [nswindow performSelector: @selector(toggleFullScreen:) withObject:nswindow];
    1.19 +    [nswindow performSelectorOnMainThread: @selector(toggleFullScreen:) withObject:nswindow waitUntilDone:NO];
    1.20      return YES;
    1.21  }
    1.22  
    1.23 @@ -433,12 +429,15 @@
    1.24              [nswindow setStyleMask:NSBorderlessWindowMask];
    1.25          }
    1.26      }
    1.27 +
    1.28      isFullscreen = YES;
    1.29      inFullscreenTransition = YES;
    1.30  }
    1.31  
    1.32  - (void)windowDidEnterFullScreen:(NSNotification *)aNotification
    1.33  {
    1.34 +    SDL_Window *window = _data->window;
    1.35 +
    1.36      inFullscreenTransition = NO;
    1.37  
    1.38      if (pendingWindowOperation == PENDING_OPERATION_LEAVE_FULLSCREEN) {
    1.39 @@ -446,6 +445,11 @@
    1.40          [self setFullscreenState:NO];
    1.41      } else {
    1.42          pendingWindowOperation = PENDING_OPERATION_NONE;
    1.43 +        /* Force the size change event in case it was delivered earlier
    1.44 +           while the window was still animating into place.
    1.45 +         */
    1.46 +        window->w = 0;
    1.47 +        window->h = 0;
    1.48          [self windowDidResize:aNotification];
    1.49      }
    1.50  }
    1.51 @@ -465,6 +469,7 @@
    1.52  
    1.53  - (void)windowDidExitFullScreen:(NSNotification *)aNotification
    1.54  {
    1.55 +    SDL_Window *window = _data->window;
    1.56      NSWindow *nswindow = _data->nswindow;
    1.57  
    1.58      inFullscreenTransition = NO;
    1.59 @@ -477,6 +482,11 @@
    1.60          [nswindow miniaturize:nil];
    1.61      } else {
    1.62          pendingWindowOperation = PENDING_OPERATION_NONE;
    1.63 +        /* Force the size change event in case it was delivered earlier
    1.64 +           while the window was still animating into place.
    1.65 +         */
    1.66 +        window->w = 0;
    1.67 +        window->h = 0;
    1.68          [self windowDidResize:aNotification];
    1.69      }
    1.70  }