Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
Fix Mac crash when creating fullscreen window introduced in 9d43403e9…
Browse files Browse the repository at this point in the history
…fc5.

makeKeyAndOrderFront: was sending three KVO transitions for isVisible,
for false -> true, true -> false, and then false -> true. This was
causing an infinite recursion.

We now suspend monitoring of the KVO before makeKeyAndOrderFront, then
resume afterwards and send any changes in isVisible's state.
  • Loading branch information
jorgenpt committed Apr 23, 2013
1 parent bc04a35 commit babe495
Showing 1 changed file with 39 additions and 2 deletions.
41 changes: 39 additions & 2 deletions src/video/cocoa/SDL_cocoawindow.m
Expand Up @@ -50,6 +50,8 @@ - (void)listen:(SDL_WindowData *)data
NSView *view = [window contentView];

_data = data;
observingVisible = YES;
wasVisible = [window isVisible];

center = [NSNotificationCenter defaultCenter];

Expand Down Expand Up @@ -90,6 +92,10 @@ - (void)observeValueForKeyPath:(NSString *)keyPath
change:(NSDictionary *)change
context:(void *)context
{
if (!observingVisible) {
return;
}

if (object == _data->nswindow && [keyPath isEqualToString:@"visible"]) {
int newVisibility = [[change objectForKey:@"new"] intValue];
if (newVisibility) {
Expand All @@ -100,6 +106,27 @@ - (void)observeValueForKeyPath:(NSString *)keyPath
}
}

-(void) pauseVisibleObservation
{
observingVisible = NO;
wasVisible = [_data->nswindow isVisible];
}

-(void) resumeVisibleObservation
{
BOOL isVisible = [_data->nswindow isVisible];
observingVisible = YES;
if (wasVisible != isVisible) {
if (isVisible) {
SDL_SendWindowEvent(_data->window, SDL_WINDOWEVENT_SHOWN, 0, 0);
} else {
SDL_SendWindowEvent(_data->window, SDL_WINDOWEVENT_HIDDEN, 0, 0);
}

wasVisible = isVisible;
}
}

- (void)close
{
NSNotificationCenter *center;
Expand Down Expand Up @@ -785,10 +812,13 @@ - (void)rightMouseDown:(NSEvent *)theEvent
Cocoa_ShowWindow(_THIS, SDL_Window * window)
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
SDL_WindowData *windowData = ((SDL_WindowData *) window->driverdata);
NSWindow *nswindow = windowData->nswindow;

if (![nswindow isMiniaturized]) {
[windowData->listener pauseVisibleObservation];
[nswindow makeKeyAndOrderFront:nil];
[windowData->listener resumeVisibleObservation];
}
[pool release];
}
Expand All @@ -807,9 +837,13 @@ - (void)rightMouseDown:(NSEvent *)theEvent
Cocoa_RaiseWindow(_THIS, SDL_Window * window)
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
SDL_WindowData *windowData = ((SDL_WindowData *) window->driverdata);
NSWindow *nswindow = windowData->nswindow;

[windowData->listener pauseVisibleObservation];
[nswindow makeKeyAndOrderFront:nil];
[windowData->listener resumeVisibleObservation];

[pool release];
}

Expand Down Expand Up @@ -960,7 +994,10 @@ - (void)rightMouseDown:(NSEvent *)theEvent
[nswindow setLevel:kCGNormalWindowLevel];
}
#endif

[data->listener pauseVisibleObservation];
[nswindow makeKeyAndOrderFront:nil];
[data->listener resumeVisibleObservation];

if (window == _this->current_glwin) {
[((NSOpenGLContext *) _this->current_glctx) update];
Expand Down

0 comments on commit babe495

Please sign in to comment.