src/video/cocoa/SDL_cocoawindow.m
changeset 7595 ede2237fcebf
parent 7594 6abcf951af68
child 7636 d5167d0818b3
     1.1 --- a/src/video/cocoa/SDL_cocoawindow.m	Wed Aug 07 16:29:21 2013 -0700
     1.2 +++ b/src/video/cocoa/SDL_cocoawindow.m	Wed Aug 07 16:29:25 2013 -0700
     1.3 @@ -42,6 +42,16 @@
     1.4      r->origin.y = CGDisplayPixelsHigh(kCGDirectMainDisplay) - r->origin.y - r->size.height;
     1.5  }
     1.6  
     1.7 +static void ScheduleContextUpdates(SDL_WindowData *data)
     1.8 +{
     1.9 +    NSMutableArray *contexts = data->nscontexts;
    1.10 +    @synchronized (contexts) {
    1.11 +        for (SDLOpenGLContext *context in contexts) {
    1.12 +            [context scheduleUpdate];
    1.13 +        }
    1.14 +    }
    1.15 +}
    1.16 +
    1.17  @implementation Cocoa_WindowListener
    1.18  
    1.19  - (void)listen:(SDL_WindowData *)data
    1.20 @@ -211,7 +221,7 @@
    1.21      x = (int)rect.origin.x;
    1.22      y = (int)rect.origin.y;
    1.23  
    1.24 -    [_data->nscontext scheduleUpdate];
    1.25 +    ScheduleContextUpdates(_data);
    1.26  
    1.27      SDL_SendWindowEvent(window, SDL_WINDOWEVENT_MOVED, x, y);
    1.28  }
    1.29 @@ -228,7 +238,7 @@
    1.30      if (SDL_IsShapedWindow(_data->window))
    1.31          Cocoa_ResizeWindowShape(_data->window);
    1.32  
    1.33 -    [_data->nscontext scheduleUpdate];
    1.34 +    ScheduleContextUpdates(_data);
    1.35  
    1.36      /* The window can move during a resize event, such as when maximizing
    1.37         or resizing from a corner */
    1.38 @@ -605,6 +615,7 @@
    1.39      data->nswindow = nswindow;
    1.40      data->created = created;
    1.41      data->videodata = videodata;
    1.42 +    data->nscontexts = [[NSMutableArray alloc] init];
    1.43  
    1.44      pool = [[NSAutoreleasePool alloc] init];
    1.45  
    1.46 @@ -799,7 +810,7 @@
    1.47      [nswindow setFrameOrigin:rect.origin];
    1.48      s_moveHack = moveHack;
    1.49  
    1.50 -    [windata->nscontext scheduleUpdate];
    1.51 +    ScheduleContextUpdates(windata);
    1.52  
    1.53      [pool release];
    1.54  }
    1.55 @@ -816,7 +827,7 @@
    1.56      size.height = window->h;
    1.57      [nswindow setContentSize:size];
    1.58  
    1.59 -    [windata->nscontext scheduleUpdate];
    1.60 +    ScheduleContextUpdates(windata);
    1.61  
    1.62      [pool release];
    1.63  }
    1.64 @@ -903,7 +914,7 @@
    1.65  
    1.66      [nswindow zoom:nil];
    1.67  
    1.68 -    [windata->nscontext scheduleUpdate];
    1.69 +    ScheduleContextUpdates(windata);
    1.70  
    1.71      [pool release];
    1.72  }
    1.73 @@ -1040,7 +1051,7 @@
    1.74      [nswindow makeKeyAndOrderFront:nil];
    1.75      [data->listener resumeVisibleObservation];
    1.76  
    1.77 -    [data->nscontext scheduleUpdate];
    1.78 +    ScheduleContextUpdates(data);
    1.79  
    1.80      [pool release];
    1.81  }
    1.82 @@ -1133,6 +1144,14 @@
    1.83          if (data->created) {
    1.84              [data->nswindow close];
    1.85          }
    1.86 +
    1.87 +        NSArray *contexts = [[data->nscontexts copy] autorelease];
    1.88 +        for (SDLOpenGLContext *context in contexts) {
    1.89 +            /* Calling setWindow:NULL causes the context to remove itself from the context list. */            
    1.90 +            [context setWindow:NULL];
    1.91 +        }
    1.92 +        [data->nscontexts release];
    1.93 +
    1.94          SDL_free(data);
    1.95      }
    1.96      [pool release];