Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
authorSam Lantinga <slouken@libsdl.org>
Mon, 11 Feb 2013 17:39:52 -0800
changeset 6848478ecc8a58b3
parent 6847 c0fa29d3fade
child 6849 b9dcf6242476
Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
src/file/cocoa/SDL_rwopsbundlesupport.m
src/video/cocoa/SDL_cocoaclipboard.m
src/video/cocoa/SDL_cocoaevents.m
src/video/cocoa/SDL_cocoakeyboard.m
src/video/cocoa/SDL_cocoamessagebox.m
src/video/cocoa/SDL_cocoamouse.m
src/video/cocoa/SDL_cocoaopengl.m
src/video/cocoa/SDL_cocoashape.m
src/video/cocoa/SDL_cocoavideo.m
src/video/cocoa/SDL_cocoawindow.m
test/automated/rwops/TestSupportRWops_Cocoa.m
     1.1 --- a/src/file/cocoa/SDL_rwopsbundlesupport.m	Mon Feb 11 17:25:58 2013 -0800
     1.2 +++ b/src/file/cocoa/SDL_rwopsbundlesupport.m	Mon Feb 11 17:39:52 2013 -0800
     1.3 @@ -20,22 +20,25 @@
     1.4  		return fopen(file, mode);
     1.5  	}
     1.6  
     1.7 -	@autoreleasepool {
     1.8 -        NSFileManager* file_manager = [NSFileManager defaultManager];
     1.9 -        NSString* resource_path = [[NSBundle mainBundle] resourcePath];
    1.10 +	NSAutoreleasePool* autorelease_pool = [[NSAutoreleasePool alloc] init];
    1.11  
    1.12 -        NSString* ns_string_file_component = [file_manager stringWithFileSystemRepresentation:file length:strlen(file)];
    1.13  
    1.14 -        NSString* full_path_with_file_to_try = [resource_path stringByAppendingPathComponent:ns_string_file_component];
    1.15 -        if([file_manager fileExistsAtPath:full_path_with_file_to_try])
    1.16 -        {
    1.17 -            fp = fopen([full_path_with_file_to_try fileSystemRepresentation], mode);
    1.18 -        }
    1.19 -        else
    1.20 -        {
    1.21 -            fp = fopen(file, mode);
    1.22 -        }
    1.23 -    }
    1.24 +	NSFileManager* file_manager = [NSFileManager defaultManager];
    1.25 +	NSString* resource_path = [[NSBundle mainBundle] resourcePath];
    1.26 +
    1.27 +	NSString* ns_string_file_component = [file_manager stringWithFileSystemRepresentation:file length:strlen(file)];
    1.28 +
    1.29 +	NSString* full_path_with_file_to_try = [resource_path stringByAppendingPathComponent:ns_string_file_component];
    1.30 +	if([file_manager fileExistsAtPath:full_path_with_file_to_try])
    1.31 +	{
    1.32 +		fp = fopen([full_path_with_file_to_try fileSystemRepresentation], mode);
    1.33 +	}
    1.34 +	else
    1.35 +	{
    1.36 +		fp = fopen(file, mode);
    1.37 +	}
    1.38 +
    1.39 +	[autorelease_pool drain];
    1.40  
    1.41  	return fp;
    1.42  }
     2.1 --- a/src/video/cocoa/SDL_cocoaclipboard.m	Mon Feb 11 17:25:58 2013 -0800
     2.2 +++ b/src/video/cocoa/SDL_cocoaclipboard.m	Mon Feb 11 17:39:52 2013 -0800
     2.3 @@ -45,46 +45,51 @@
     2.4  Cocoa_SetClipboardText(_THIS, const char *text)
     2.5  {
     2.6      SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
     2.7 -
     2.8 +    NSAutoreleasePool *pool;
     2.9      NSPasteboard *pasteboard;
    2.10      NSString *format = GetTextFormat(_this);
    2.11  
    2.12 -    @autoreleasepool {
    2.13 -        pasteboard = [NSPasteboard generalPasteboard];
    2.14 -        data->clipboard_count = [pasteboard declareTypes:[NSArray arrayWithObject:format] owner:nil];
    2.15 -        [pasteboard setString:[NSString stringWithUTF8String:text] forType:format];
    2.16 -    }
    2.17 -    
    2.18 +    pool = [[NSAutoreleasePool alloc] init];
    2.19 +
    2.20 +    pasteboard = [NSPasteboard generalPasteboard];
    2.21 +    data->clipboard_count = [pasteboard declareTypes:[NSArray arrayWithObject:format] owner:nil];
    2.22 +    [pasteboard setString:[NSString stringWithUTF8String:text] forType:format];
    2.23 +
    2.24 +    [pool release];
    2.25 +
    2.26      return 0;
    2.27  }
    2.28  
    2.29  char *
    2.30  Cocoa_GetClipboardText(_THIS)
    2.31  {
    2.32 +    NSAutoreleasePool *pool;
    2.33      NSPasteboard *pasteboard;
    2.34      NSString *format = GetTextFormat(_this);
    2.35      NSString *available;
    2.36      char *text;
    2.37  
    2.38 -    @autoreleasepool {
    2.39 -        pasteboard = [NSPasteboard generalPasteboard];
    2.40 -        available = [pasteboard availableTypeFromArray: [NSArray arrayWithObject:format]];
    2.41 -        if ([available isEqualToString:format]) {
    2.42 -            NSString* string;
    2.43 -            const char *utf8;
    2.44 +    pool = [[NSAutoreleasePool alloc] init];
    2.45  
    2.46 -            string = [pasteboard stringForType:format];
    2.47 -            if (string == nil) {
    2.48 -                utf8 = "";
    2.49 -            } else {
    2.50 -                utf8 = [string UTF8String];
    2.51 -            }
    2.52 -            text = SDL_strdup(utf8);
    2.53 +    pasteboard = [NSPasteboard generalPasteboard];
    2.54 +    available = [pasteboard availableTypeFromArray: [NSArray arrayWithObject:format]];
    2.55 +    if ([available isEqualToString:format]) {
    2.56 +        NSString* string;
    2.57 +        const char *utf8;
    2.58 +
    2.59 +        string = [pasteboard stringForType:format];
    2.60 +        if (string == nil) {
    2.61 +            utf8 = "";
    2.62          } else {
    2.63 -            text = SDL_strdup("");
    2.64 +            utf8 = [string UTF8String];
    2.65          }
    2.66 +        text = SDL_strdup(utf8);
    2.67 +    } else {
    2.68 +        text = SDL_strdup("");
    2.69      }
    2.70 -    
    2.71 +
    2.72 +    [pool release];
    2.73 +
    2.74      return text;
    2.75  }
    2.76  
    2.77 @@ -103,19 +108,22 @@
    2.78  void
    2.79  Cocoa_CheckClipboardUpdate(struct SDL_VideoData * data)
    2.80  {
    2.81 +    NSAutoreleasePool *pool;
    2.82      NSPasteboard *pasteboard;
    2.83      NSInteger count;
    2.84  
    2.85 -    @autoreleasepool {
    2.86 -        pasteboard = [NSPasteboard generalPasteboard];
    2.87 -        count = [pasteboard changeCount];
    2.88 -        if (count != data->clipboard_count) {
    2.89 -            if (data->clipboard_count) {
    2.90 -                SDL_SendClipboardUpdate();
    2.91 -            }
    2.92 -            data->clipboard_count = count;
    2.93 +    pool = [[NSAutoreleasePool alloc] init];
    2.94 +
    2.95 +    pasteboard = [NSPasteboard generalPasteboard];
    2.96 +    count = [pasteboard changeCount];
    2.97 +    if (count != data->clipboard_count) {
    2.98 +        if (data->clipboard_count) {
    2.99 +            SDL_SendClipboardUpdate();
   2.100          }
   2.101 +        data->clipboard_count = count;
   2.102      }
   2.103 +
   2.104 +    [pool release];
   2.105  }
   2.106  
   2.107  #endif /* SDL_VIDEO_DRIVER_COCOA */
     3.1 --- a/src/video/cocoa/SDL_cocoaevents.m	Mon Feb 11 17:25:58 2013 -0800
     3.2 +++ b/src/video/cocoa/SDL_cocoaevents.m	Mon Feb 11 17:39:52 2013 -0800
     3.3 @@ -159,30 +159,33 @@
     3.4  {
     3.5      /* This can get called more than once! Be careful what you initialize! */
     3.6      ProcessSerialNumber psn;
     3.7 +    NSAutoreleasePool *pool;
     3.8  
     3.9      if (!GetCurrentProcess(&psn)) {
    3.10          TransformProcessType(&psn, kProcessTransformToForegroundApplication);
    3.11          SetFrontProcess(&psn);
    3.12      }
    3.13  
    3.14 -    @autoreleasepool {
    3.15 -        if (NSApp == nil) {
    3.16 -            [NSApplication sharedApplication];
    3.17 +    pool = [[NSAutoreleasePool alloc] init];
    3.18 +    if (NSApp == nil) {
    3.19 +        [NSApplication sharedApplication];
    3.20  
    3.21 -            if ([NSApp mainMenu] == nil) {
    3.22 -                CreateApplicationMenus();
    3.23 -            }
    3.24 -            [NSApp finishLaunching];
    3.25 +        if ([NSApp mainMenu] == nil) {
    3.26 +            CreateApplicationMenus();
    3.27          }
    3.28 -        if ([NSApp delegate] == nil) {
    3.29 -            [NSApp setDelegate:[[SDLAppDelegate alloc] init]];
    3.30 -        }
    3.31 +        [NSApp finishLaunching];
    3.32      }
    3.33 +    if ([NSApp delegate] == nil) {
    3.34 +        [NSApp setDelegate:[[SDLAppDelegate alloc] init]];
    3.35 +    }
    3.36 +    [pool release];
    3.37  }
    3.38  
    3.39  void
    3.40  Cocoa_PumpEvents(_THIS)
    3.41  {
    3.42 +    NSAutoreleasePool *pool;
    3.43 +
    3.44      /* Update activity every 30 seconds to prevent screensaver */
    3.45      if (_this->suspend_screensaver) {
    3.46          SDL_VideoData *data = (SDL_VideoData *)_this->driverdata;
    3.47 @@ -194,39 +197,39 @@
    3.48          }
    3.49      }
    3.50  
    3.51 -    @autoreleasepool {
    3.52 -        for ( ; ; ) {
    3.53 -            NSEvent *event = [NSApp nextEventMatchingMask:NSAnyEventMask untilDate:[NSDate distantPast] inMode:NSDefaultRunLoopMode dequeue:YES ];
    3.54 -            if ( event == nil ) {
    3.55 -                break;
    3.56 -            }
    3.57 -            
    3.58 -            switch ([event type]) {
    3.59 -            case NSLeftMouseDown:
    3.60 -            case NSOtherMouseDown:
    3.61 -            case NSRightMouseDown:
    3.62 -            case NSLeftMouseUp:
    3.63 -            case NSOtherMouseUp:
    3.64 -            case NSRightMouseUp:
    3.65 -            case NSLeftMouseDragged:
    3.66 -            case NSRightMouseDragged:
    3.67 -            case NSOtherMouseDragged: /* usually middle mouse dragged */
    3.68 -            case NSMouseMoved:
    3.69 -            case NSScrollWheel:
    3.70 -                Cocoa_HandleMouseEvent(_this, event);
    3.71 -                break;
    3.72 -            case NSKeyDown:
    3.73 -            case NSKeyUp:
    3.74 -            case NSFlagsChanged:
    3.75 -                Cocoa_HandleKeyEvent(_this, event);
    3.76 -                break;
    3.77 -            default:
    3.78 -                break;
    3.79 -            }
    3.80 -            /* Pass through to NSApp to make sure everything stays in sync */
    3.81 -            [NSApp sendEvent:event];
    3.82 +    pool = [[NSAutoreleasePool alloc] init];
    3.83 +    for ( ; ; ) {
    3.84 +        NSEvent *event = [NSApp nextEventMatchingMask:NSAnyEventMask untilDate:[NSDate distantPast] inMode:NSDefaultRunLoopMode dequeue:YES ];
    3.85 +        if ( event == nil ) {
    3.86 +            break;
    3.87          }
    3.88 +		
    3.89 +        switch ([event type]) {
    3.90 +        case NSLeftMouseDown:
    3.91 +        case NSOtherMouseDown:
    3.92 +        case NSRightMouseDown:
    3.93 +        case NSLeftMouseUp:
    3.94 +        case NSOtherMouseUp:
    3.95 +        case NSRightMouseUp:
    3.96 +        case NSLeftMouseDragged:
    3.97 +        case NSRightMouseDragged:
    3.98 +        case NSOtherMouseDragged: /* usually middle mouse dragged */
    3.99 +        case NSMouseMoved:
   3.100 +        case NSScrollWheel:
   3.101 +            Cocoa_HandleMouseEvent(_this, event);
   3.102 +            break;
   3.103 +        case NSKeyDown:
   3.104 +        case NSKeyUp:
   3.105 +        case NSFlagsChanged:
   3.106 +            Cocoa_HandleKeyEvent(_this, event);
   3.107 +            break;
   3.108 +        default:
   3.109 +            break;
   3.110 +        }
   3.111 +        /* Pass through to NSApp to make sure everything stays in sync */
   3.112 +        [NSApp sendEvent:event];
   3.113      }
   3.114 +    [pool release];
   3.115  }
   3.116  
   3.117  #endif /* SDL_VIDEO_DRIVER_COCOA */
     4.1 --- a/src/video/cocoa/SDL_cocoakeyboard.m	Mon Feb 11 17:25:58 2013 -0800
     4.2 +++ b/src/video/cocoa/SDL_cocoakeyboard.m	Mon Feb 11 17:39:52 2013 -0800
     4.3 @@ -625,27 +625,28 @@
     4.4  Cocoa_StartTextInput(_THIS)
     4.5  {
     4.6      SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
     4.7 -    @autoreleasepool {
     4.8 -        NSView *parentView = [[NSApp keyWindow] contentView];
     4.9 +    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    4.10 +    NSView *parentView = [[NSApp keyWindow] contentView];
    4.11  
    4.12 -        /* We only keep one field editor per process, since only the front most
    4.13 -         * window can receive text input events, so it make no sense to keep more
    4.14 -         * than one copy. When we switched to another window and requesting for
    4.15 -         * text input, simply remove the field editor from its superview then add
    4.16 -         * it to the front most window's content view */
    4.17 -        if (!data->fieldEdit) {
    4.18 -            data->fieldEdit =
    4.19 -                [[SDLTranslatorResponder alloc] initWithFrame: NSMakeRect(0.0, 0.0, 0.0, 0.0)];
    4.20 -        }
    4.21 +    /* We only keep one field editor per process, since only the front most
    4.22 +     * window can receive text input events, so it make no sense to keep more
    4.23 +     * than one copy. When we switched to another window and requesting for
    4.24 +     * text input, simply remove the field editor from its superview then add
    4.25 +     * it to the front most window's content view */
    4.26 +    if (!data->fieldEdit) {
    4.27 +        data->fieldEdit =
    4.28 +            [[SDLTranslatorResponder alloc] initWithFrame: NSMakeRect(0.0, 0.0, 0.0, 0.0)];
    4.29 +    }
    4.30  
    4.31 -        if (![[data->fieldEdit superview] isEqual: parentView])
    4.32 -        {
    4.33 -            // DEBUG_IME(@"add fieldEdit to window contentView");
    4.34 -            [data->fieldEdit removeFromSuperview];
    4.35 -            [parentView addSubview: data->fieldEdit];
    4.36 -            [[NSApp keyWindow] makeFirstResponder: data->fieldEdit];
    4.37 -        }
    4.38 +    if (![[data->fieldEdit superview] isEqual: parentView])
    4.39 +    {
    4.40 +        // DEBUG_IME(@"add fieldEdit to window contentView");
    4.41 +        [data->fieldEdit removeFromSuperview];
    4.42 +        [parentView addSubview: data->fieldEdit];
    4.43 +        [[NSApp keyWindow] makeFirstResponder: data->fieldEdit];
    4.44      }
    4.45 +
    4.46 +    [pool release];
    4.47  }
    4.48  
    4.49  void
    4.50 @@ -654,11 +655,11 @@
    4.51      SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
    4.52  
    4.53      if (data && data->fieldEdit) {
    4.54 -        @autoreleasepool {
    4.55 -            [data->fieldEdit removeFromSuperview];
    4.56 -            [data->fieldEdit release];
    4.57 -            data->fieldEdit = nil;
    4.58 -        }
    4.59 +        NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    4.60 +        [data->fieldEdit removeFromSuperview];
    4.61 +        [data->fieldEdit release];
    4.62 +        data->fieldEdit = nil;
    4.63 +        [pool release];
    4.64      }
    4.65  }
    4.66  
     5.1 --- a/src/video/cocoa/SDL_cocoamessagebox.m	Mon Feb 11 17:25:58 2013 -0800
     5.2 +++ b/src/video/cocoa/SDL_cocoamessagebox.m	Mon Feb 11 17:39:52 2013 -0800
     5.3 @@ -39,38 +39,40 @@
     5.4  {
     5.5      Cocoa_RegisterApp();
     5.6  
     5.7 -    @autoreleasepool {
     5.8 -        NSAlert* alert = [[NSAlert alloc] init];
     5.9 +    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    5.10  
    5.11 -        if (messageboxdata->flags & SDL_MESSAGEBOX_ERROR) {
    5.12 -            [alert setAlertStyle:NSCriticalAlertStyle];
    5.13 -        } else if (messageboxdata->flags & SDL_MESSAGEBOX_WARNING) {
    5.14 -            [alert setAlertStyle:NSWarningAlertStyle];
    5.15 +    NSAlert* alert = [[NSAlert alloc] init];
    5.16 +
    5.17 +    if (messageboxdata->flags & SDL_MESSAGEBOX_ERROR) {
    5.18 +        [alert setAlertStyle:NSCriticalAlertStyle];
    5.19 +    } else if (messageboxdata->flags & SDL_MESSAGEBOX_WARNING) {
    5.20 +        [alert setAlertStyle:NSWarningAlertStyle];
    5.21 +    } else {
    5.22 +        [alert setAlertStyle:NSInformationalAlertStyle];
    5.23 +    }
    5.24 +
    5.25 +    [alert setMessageText:[NSString stringWithUTF8String:messageboxdata->title]];
    5.26 +    [alert setInformativeText:[NSString stringWithUTF8String:messageboxdata->message]];
    5.27 +
    5.28 +    const SDL_MessageBoxButtonData *buttons = messageboxdata->buttons;
    5.29 +    int i;
    5.30 +    for (i = 0; i < messageboxdata->numbuttons; ++i) {
    5.31 +        NSButton *button = [alert addButtonWithTitle:[NSString stringWithUTF8String:buttons[i].text]];
    5.32 +        if (buttons[i].flags & SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT) {
    5.33 +            [button setKeyEquivalent:@"\r"];
    5.34 +        } else if (buttons[i].flags & SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT) {
    5.35 +            [button setKeyEquivalent:@"\033"];
    5.36          } else {
    5.37 -            [alert setAlertStyle:NSInformationalAlertStyle];
    5.38 +            [button setKeyEquivalent:@""];
    5.39          }
    5.40 +    }
    5.41  
    5.42 -        [alert setMessageText:[NSString stringWithUTF8String:messageboxdata->title]];
    5.43 -        [alert setInformativeText:[NSString stringWithUTF8String:messageboxdata->message]];
    5.44 +    NSInteger clicked = [alert runModal];
    5.45 +    clicked -= NSAlertFirstButtonReturn;
    5.46 +    *buttonid = buttons[clicked].buttonid;
    5.47 +    [alert release];
    5.48  
    5.49 -        const SDL_MessageBoxButtonData *buttons = messageboxdata->buttons;
    5.50 -        int i;
    5.51 -        for (i = 0; i < messageboxdata->numbuttons; ++i) {
    5.52 -            NSButton *button = [alert addButtonWithTitle:[NSString stringWithUTF8String:buttons[i].text]];
    5.53 -            if (buttons[i].flags & SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT) {
    5.54 -                [button setKeyEquivalent:@"\r"];
    5.55 -            } else if (buttons[i].flags & SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT) {
    5.56 -                [button setKeyEquivalent:@"\033"];
    5.57 -            } else {
    5.58 -                [button setKeyEquivalent:@""];
    5.59 -            }
    5.60 -        }
    5.61 -
    5.62 -        NSInteger clicked = [alert runModal];
    5.63 -        clicked -= NSAlertFirstButtonReturn;
    5.64 -        *buttonid = buttons[clicked].buttonid;
    5.65 -        [alert release];
    5.66 -    }
    5.67 +    [pool release];
    5.68  
    5.69      return 0;
    5.70  }
     6.1 --- a/src/video/cocoa/SDL_cocoamouse.m	Mon Feb 11 17:25:58 2013 -0800
     6.2 +++ b/src/video/cocoa/SDL_cocoamouse.m	Mon Feb 11 17:39:52 2013 -0800
     6.3 @@ -32,134 +32,140 @@
     6.4  static SDL_Cursor *
     6.5  Cocoa_CreateDefaultCursor()
     6.6  {
     6.7 -    @autoreleasepool {
     6.8 -        NSCursor *nscursor;
     6.9 -        SDL_Cursor *cursor = NULL;
    6.10 +    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    6.11 +    NSCursor *nscursor;
    6.12 +    SDL_Cursor *cursor = NULL;
    6.13  
    6.14 -        nscursor = [NSCursor arrowCursor];
    6.15 +    nscursor = [NSCursor arrowCursor];
    6.16  
    6.17 -        if (nscursor) {
    6.18 -            cursor = SDL_calloc(1, sizeof(*cursor));
    6.19 -            if (cursor) {
    6.20 -                cursor->driverdata = nscursor;
    6.21 -                [nscursor retain];
    6.22 -            }
    6.23 +    if (nscursor) {
    6.24 +        cursor = SDL_calloc(1, sizeof(*cursor));
    6.25 +        if (cursor) {
    6.26 +            cursor->driverdata = nscursor;
    6.27 +            [nscursor retain];
    6.28          }
    6.29 -        
    6.30 -        return cursor;
    6.31      }
    6.32 +
    6.33 +    [pool release];
    6.34 +
    6.35 +    return cursor;
    6.36  }
    6.37  
    6.38  static SDL_Cursor *
    6.39  Cocoa_CreateCursor(SDL_Surface * surface, int hot_x, int hot_y)
    6.40  {
    6.41 -    @autoreleasepool {
    6.42 -        NSImage *nsimage;
    6.43 -        NSCursor *nscursor = NULL;
    6.44 -        SDL_Cursor *cursor = NULL;
    6.45 +    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    6.46 +    NSImage *nsimage;
    6.47 +    NSCursor *nscursor = NULL;
    6.48 +    SDL_Cursor *cursor = NULL;
    6.49  
    6.50 -        nsimage = Cocoa_CreateImage(surface);
    6.51 -        if (nsimage) {
    6.52 -            nscursor = [[NSCursor alloc] initWithImage: nsimage hotSpot: NSMakePoint(hot_x, hot_y)];
    6.53 +    nsimage = Cocoa_CreateImage(surface);
    6.54 +    if (nsimage) {
    6.55 +        nscursor = [[NSCursor alloc] initWithImage: nsimage hotSpot: NSMakePoint(hot_x, hot_y)];
    6.56 +    }
    6.57 +
    6.58 +    if (nscursor) {
    6.59 +        cursor = SDL_calloc(1, sizeof(*cursor));
    6.60 +        if (cursor) {
    6.61 +            cursor->driverdata = nscursor;
    6.62          }
    6.63 +    }
    6.64  
    6.65 -        if (nscursor) {
    6.66 -            cursor = SDL_calloc(1, sizeof(*cursor));
    6.67 -            if (cursor) {
    6.68 -                cursor->driverdata = nscursor;
    6.69 -            }
    6.70 -        }
    6.71 -        
    6.72 -        return cursor;
    6.73 -    }
    6.74 +    [pool release];
    6.75 +
    6.76 +    return cursor;
    6.77  }
    6.78  
    6.79  static SDL_Cursor *
    6.80  Cocoa_CreateSystemCursor(SDL_SystemCursor id)
    6.81  {
    6.82 -    @autoreleasepool {
    6.83 -        NSCursor *nscursor = NULL;
    6.84 -        SDL_Cursor *cursor = NULL;
    6.85 +    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    6.86 +    NSCursor *nscursor = NULL;
    6.87 +    SDL_Cursor *cursor = NULL;
    6.88  
    6.89 -        switch(id)
    6.90 -        {
    6.91 -        case SDL_SYSTEM_CURSOR_ARROW:
    6.92 -            nscursor = [NSCursor arrowCursor];
    6.93 -            break;
    6.94 -        case SDL_SYSTEM_CURSOR_IBEAM:
    6.95 -            nscursor = [NSCursor IBeamCursor];
    6.96 -            break;
    6.97 -        case SDL_SYSTEM_CURSOR_WAIT:
    6.98 -            nscursor = [NSCursor arrowCursor];
    6.99 -            break;
   6.100 -        case SDL_SYSTEM_CURSOR_CROSSHAIR:
   6.101 -            nscursor = [NSCursor crosshairCursor];
   6.102 -            break;
   6.103 -        case SDL_SYSTEM_CURSOR_WAITARROW:
   6.104 -            nscursor = [NSCursor arrowCursor];
   6.105 -            break;
   6.106 -        case SDL_SYSTEM_CURSOR_SIZENWSE:
   6.107 -        case SDL_SYSTEM_CURSOR_SIZENESW:
   6.108 -            nscursor = [NSCursor closedHandCursor];
   6.109 -            break;
   6.110 -        case SDL_SYSTEM_CURSOR_SIZEWE:
   6.111 -            nscursor = [NSCursor resizeLeftRightCursor];
   6.112 -            break;
   6.113 -        case SDL_SYSTEM_CURSOR_SIZENS:
   6.114 -            nscursor = [NSCursor resizeUpDownCursor];
   6.115 -            break;
   6.116 -        case SDL_SYSTEM_CURSOR_SIZEALL:
   6.117 -            nscursor = [NSCursor closedHandCursor];
   6.118 -            break;
   6.119 -        case SDL_SYSTEM_CURSOR_NO:
   6.120 -            nscursor = [NSCursor operationNotAllowedCursor];
   6.121 -            break;
   6.122 -        case SDL_SYSTEM_CURSOR_HAND:
   6.123 -            nscursor = [NSCursor pointingHandCursor];
   6.124 -            break;
   6.125 -        default:
   6.126 -            SDL_assert(!"Unknown system cursor");
   6.127 -            return NULL;
   6.128 +    switch(id)
   6.129 +    {
   6.130 +    case SDL_SYSTEM_CURSOR_ARROW:
   6.131 +        nscursor = [NSCursor arrowCursor];
   6.132 +        break;
   6.133 +    case SDL_SYSTEM_CURSOR_IBEAM:
   6.134 +        nscursor = [NSCursor IBeamCursor];
   6.135 +        break;
   6.136 +    case SDL_SYSTEM_CURSOR_WAIT:
   6.137 +        nscursor = [NSCursor arrowCursor];
   6.138 +        break;
   6.139 +    case SDL_SYSTEM_CURSOR_CROSSHAIR:
   6.140 +        nscursor = [NSCursor crosshairCursor];
   6.141 +        break;
   6.142 +    case SDL_SYSTEM_CURSOR_WAITARROW:
   6.143 +        nscursor = [NSCursor arrowCursor];
   6.144 +        break;
   6.145 +    case SDL_SYSTEM_CURSOR_SIZENWSE:
   6.146 +    case SDL_SYSTEM_CURSOR_SIZENESW:
   6.147 +        nscursor = [NSCursor closedHandCursor];
   6.148 +        break;
   6.149 +    case SDL_SYSTEM_CURSOR_SIZEWE:
   6.150 +        nscursor = [NSCursor resizeLeftRightCursor];
   6.151 +        break;
   6.152 +    case SDL_SYSTEM_CURSOR_SIZENS:
   6.153 +        nscursor = [NSCursor resizeUpDownCursor];
   6.154 +        break;
   6.155 +    case SDL_SYSTEM_CURSOR_SIZEALL:
   6.156 +        nscursor = [NSCursor closedHandCursor];
   6.157 +        break;
   6.158 +    case SDL_SYSTEM_CURSOR_NO:
   6.159 +        nscursor = [NSCursor operationNotAllowedCursor];
   6.160 +        break;
   6.161 +    case SDL_SYSTEM_CURSOR_HAND:
   6.162 +        nscursor = [NSCursor pointingHandCursor];
   6.163 +        break;
   6.164 +    default:
   6.165 +        SDL_assert(!"Unknown system cursor");
   6.166 +        return NULL;
   6.167 +    }
   6.168 +
   6.169 +    if (nscursor) {
   6.170 +        cursor = SDL_calloc(1, sizeof(*cursor));
   6.171 +        if (cursor) {
   6.172 +            // We'll free it later, so retain it here
   6.173 +            [nscursor retain];
   6.174 +            cursor->driverdata = nscursor;
   6.175          }
   6.176 +    }
   6.177  
   6.178 -        if (nscursor) {
   6.179 -            cursor = SDL_calloc(1, sizeof(*cursor));
   6.180 -            if (cursor) {
   6.181 -                // We'll free it later, so retain it here
   6.182 -                [nscursor retain];
   6.183 -                cursor->driverdata = nscursor;
   6.184 -            }
   6.185 -        }
   6.186 -            
   6.187 -        return cursor;
   6.188 -    }
   6.189 +    [pool release];
   6.190 +
   6.191 +    return cursor;
   6.192  }
   6.193  
   6.194  static void
   6.195  Cocoa_FreeCursor(SDL_Cursor * cursor)
   6.196  {
   6.197 -    @autoreleasepool {
   6.198 -        NSCursor *nscursor = (NSCursor *)cursor->driverdata;
   6.199 +    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
   6.200 +    NSCursor *nscursor = (NSCursor *)cursor->driverdata;
   6.201  
   6.202 -        [nscursor release];
   6.203 -        SDL_free(cursor);
   6.204 -    }
   6.205 +    [nscursor release];
   6.206 +    SDL_free(cursor);
   6.207 +
   6.208 +    [pool release];
   6.209  }
   6.210  
   6.211  static int
   6.212  Cocoa_ShowCursor(SDL_Cursor * cursor)
   6.213  {
   6.214 -    @autoreleasepool {
   6.215 -        if (cursor) {
   6.216 -            NSCursor *nscursor = (NSCursor *)cursor->driverdata;
   6.217 +    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
   6.218  
   6.219 -            [nscursor set];
   6.220 -            [NSCursor unhide];
   6.221 -        } else {
   6.222 -            [NSCursor hide];
   6.223 -        }
   6.224 +    if (cursor) {
   6.225 +        NSCursor *nscursor = (NSCursor *)cursor->driverdata;
   6.226 +
   6.227 +        [nscursor set];
   6.228 +        [NSCursor unhide];
   6.229 +    } else {
   6.230 +        [NSCursor hide];
   6.231      }
   6.232  
   6.233 +    [pool release];
   6.234 +
   6.235      return 0;
   6.236  }
   6.237  
     7.1 --- a/src/video/cocoa/SDL_cocoaopengl.m	Mon Feb 11 17:25:58 2013 -0800
     7.2 +++ b/src/video/cocoa/SDL_cocoaopengl.m	Mon Feb 11 17:39:52 2013 -0800
     7.3 @@ -80,6 +80,7 @@
     7.4      const int wantver = (_this->gl_config.major_version << 8) |
     7.5                          (_this->gl_config.minor_version);
     7.6      SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
     7.7 +    NSAutoreleasePool *pool;
     7.8      SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
     7.9      SDL_DisplayData *displaydata = (SDL_DisplayData *)display->driverdata;
    7.10      NSOpenGLPixelFormatAttribute attr[32];
    7.11 @@ -99,115 +100,120 @@
    7.12          return NULL;
    7.13      }
    7.14  
    7.15 -    @autoreleasepool {
    7.16 -        /* specify a profile if we're on Lion (10.7) or later. */
    7.17 -        if (data->osversion >= 0x1070) {
    7.18 -            NSOpenGLPixelFormatAttribute profile = kCGLOGLPVersion_Legacy;
    7.19 -            if (_this->gl_config.profile_mask == SDL_GL_CONTEXT_PROFILE_CORE) {
    7.20 -                if (wantver == 0x0302) {
    7.21 -                    profile = kCGLOGLPVersion_3_2_Core;
    7.22 -                }
    7.23 +    pool = [[NSAutoreleasePool alloc] init];
    7.24 +
    7.25 +    /* specify a profile if we're on Lion (10.7) or later. */
    7.26 +    if (data->osversion >= 0x1070) {
    7.27 +        NSOpenGLPixelFormatAttribute profile = kCGLOGLPVersion_Legacy;
    7.28 +        if (_this->gl_config.profile_mask == SDL_GL_CONTEXT_PROFILE_CORE) {
    7.29 +            if (wantver == 0x0302) {
    7.30 +                profile = kCGLOGLPVersion_3_2_Core;
    7.31              }
    7.32 -            attr[i++] = kCGLPFAOpenGLProfile;
    7.33 -            attr[i++] = profile;
    7.34          }
    7.35 +        attr[i++] = kCGLPFAOpenGLProfile;
    7.36 +        attr[i++] = profile;
    7.37 +    }
    7.38  
    7.39 -    #ifndef FULLSCREEN_TOGGLEABLE
    7.40 -        if (window->flags & SDL_WINDOW_FULLSCREEN) {
    7.41 -            attr[i++] = NSOpenGLPFAFullScreen;
    7.42 +#ifndef FULLSCREEN_TOGGLEABLE
    7.43 +    if (window->flags & SDL_WINDOW_FULLSCREEN) {
    7.44 +        attr[i++] = NSOpenGLPFAFullScreen;
    7.45 +    }
    7.46 +#endif
    7.47 +
    7.48 +    attr[i++] = NSOpenGLPFAColorSize;
    7.49 +    attr[i++] = SDL_BYTESPERPIXEL(display->current_mode.format)*8;
    7.50 +
    7.51 +    attr[i++] = NSOpenGLPFADepthSize;
    7.52 +    attr[i++] = _this->gl_config.depth_size;
    7.53 +
    7.54 +    if (_this->gl_config.double_buffer) {
    7.55 +        attr[i++] = NSOpenGLPFADoubleBuffer;
    7.56 +    }
    7.57 +
    7.58 +    if (_this->gl_config.stereo) {
    7.59 +        attr[i++] = NSOpenGLPFAStereo;
    7.60 +    }
    7.61 +
    7.62 +    if (_this->gl_config.stencil_size) {
    7.63 +        attr[i++] = NSOpenGLPFAStencilSize;
    7.64 +        attr[i++] = _this->gl_config.stencil_size;
    7.65 +    }
    7.66 +
    7.67 +    if ((_this->gl_config.accum_red_size +
    7.68 +         _this->gl_config.accum_green_size +
    7.69 +         _this->gl_config.accum_blue_size +
    7.70 +         _this->gl_config.accum_alpha_size) > 0) {
    7.71 +        attr[i++] = NSOpenGLPFAAccumSize;
    7.72 +        attr[i++] = _this->gl_config.accum_red_size + _this->gl_config.accum_green_size + _this->gl_config.accum_blue_size + _this->gl_config.accum_alpha_size;
    7.73 +    }
    7.74 +
    7.75 +    if (_this->gl_config.multisamplebuffers) {
    7.76 +        attr[i++] = NSOpenGLPFASampleBuffers;
    7.77 +        attr[i++] = _this->gl_config.multisamplebuffers;
    7.78 +    }
    7.79 +
    7.80 +    if (_this->gl_config.multisamplesamples) {
    7.81 +        attr[i++] = NSOpenGLPFASamples;
    7.82 +        attr[i++] = _this->gl_config.multisamplesamples;
    7.83 +        attr[i++] = NSOpenGLPFANoRecovery;
    7.84 +    }
    7.85 +
    7.86 +    if (_this->gl_config.accelerated >= 0) {
    7.87 +        if (_this->gl_config.accelerated) {
    7.88 +            attr[i++] = NSOpenGLPFAAccelerated;
    7.89 +        } else {
    7.90 +            attr[i++] = NSOpenGLPFARendererID;
    7.91 +            attr[i++] = kCGLRendererGenericFloatID;
    7.92          }
    7.93 +    }
    7.94 +
    7.95 +    attr[i++] = NSOpenGLPFAScreenMask;
    7.96 +    attr[i++] = CGDisplayIDToOpenGLDisplayMask(displaydata->display);
    7.97 +    attr[i] = 0;
    7.98 +
    7.99 +    fmt = [[NSOpenGLPixelFormat alloc] initWithAttributes:attr];
   7.100 +    if (fmt == nil) {
   7.101 +        SDL_SetError ("Failed creating OpenGL pixel format");
   7.102 +        [pool release];
   7.103 +        return NULL;
   7.104 +    }
   7.105 +
   7.106 +    context = [[NSOpenGLContext alloc] initWithFormat:fmt shareContext:nil];
   7.107 +
   7.108 +    [fmt release];
   7.109 +
   7.110 +    if (context == nil) {
   7.111 +        SDL_SetError ("Failed creating OpenGL context");
   7.112 +        [pool release];
   7.113 +        return NULL;
   7.114 +    }
   7.115 +
   7.116 +    /*
   7.117 +     * Wisdom from Apple engineer in reference to UT2003's OpenGL performance:
   7.118 +     *  "You are blowing a couple of the internal OpenGL function caches. This
   7.119 +     *  appears to be happening in the VAO case.  You can tell OpenGL to up
   7.120 +     *  the cache size by issuing the following calls right after you create
   7.121 +     *  the OpenGL context.  The default cache size is 16."    --ryan.
   7.122 +     */
   7.123 +
   7.124 +    #ifndef GLI_ARRAY_FUNC_CACHE_MAX
   7.125 +    #define GLI_ARRAY_FUNC_CACHE_MAX 284
   7.126      #endif
   7.127  
   7.128 -        attr[i++] = NSOpenGLPFAColorSize;
   7.129 -        attr[i++] = SDL_BYTESPERPIXEL(display->current_mode.format)*8;
   7.130 +    #ifndef GLI_SUBMIT_FUNC_CACHE_MAX
   7.131 +    #define GLI_SUBMIT_FUNC_CACHE_MAX 280
   7.132 +    #endif
   7.133  
   7.134 -        attr[i++] = NSOpenGLPFADepthSize;
   7.135 -        attr[i++] = _this->gl_config.depth_size;
   7.136 +    {
   7.137 +        GLint cache_max = 64;
   7.138 +        CGLContextObj ctx = [context CGLContextObj];
   7.139 +        CGLSetParameter (ctx, GLI_SUBMIT_FUNC_CACHE_MAX, &cache_max);
   7.140 +        CGLSetParameter (ctx, GLI_ARRAY_FUNC_CACHE_MAX, &cache_max);
   7.141 +    }
   7.142  
   7.143 -        if (_this->gl_config.double_buffer) {
   7.144 -            attr[i++] = NSOpenGLPFADoubleBuffer;
   7.145 -        }
   7.146 +    /* End Wisdom from Apple Engineer section. --ryan. */
   7.147  
   7.148 -        if (_this->gl_config.stereo) {
   7.149 -            attr[i++] = NSOpenGLPFAStereo;
   7.150 -        }
   7.151 -
   7.152 -        if (_this->gl_config.stencil_size) {
   7.153 -            attr[i++] = NSOpenGLPFAStencilSize;
   7.154 -            attr[i++] = _this->gl_config.stencil_size;
   7.155 -        }
   7.156 -
   7.157 -        if ((_this->gl_config.accum_red_size +
   7.158 -             _this->gl_config.accum_green_size +
   7.159 -             _this->gl_config.accum_blue_size +
   7.160 -             _this->gl_config.accum_alpha_size) > 0) {
   7.161 -            attr[i++] = NSOpenGLPFAAccumSize;
   7.162 -            attr[i++] = _this->gl_config.accum_red_size + _this->gl_config.accum_green_size + _this->gl_config.accum_blue_size + _this->gl_config.accum_alpha_size;
   7.163 -        }
   7.164 -
   7.165 -        if (_this->gl_config.multisamplebuffers) {
   7.166 -            attr[i++] = NSOpenGLPFASampleBuffers;
   7.167 -            attr[i++] = _this->gl_config.multisamplebuffers;
   7.168 -        }
   7.169 -
   7.170 -        if (_this->gl_config.multisamplesamples) {
   7.171 -            attr[i++] = NSOpenGLPFASamples;
   7.172 -            attr[i++] = _this->gl_config.multisamplesamples;
   7.173 -            attr[i++] = NSOpenGLPFANoRecovery;
   7.174 -        }
   7.175 -
   7.176 -        if (_this->gl_config.accelerated >= 0) {
   7.177 -            if (_this->gl_config.accelerated) {
   7.178 -                attr[i++] = NSOpenGLPFAAccelerated;
   7.179 -            } else {
   7.180 -                attr[i++] = NSOpenGLPFARendererID;
   7.181 -                attr[i++] = kCGLRendererGenericFloatID;
   7.182 -            }
   7.183 -        }
   7.184 -
   7.185 -        attr[i++] = NSOpenGLPFAScreenMask;
   7.186 -        attr[i++] = CGDisplayIDToOpenGLDisplayMask(displaydata->display);
   7.187 -        attr[i] = 0;
   7.188 -
   7.189 -        fmt = [[NSOpenGLPixelFormat alloc] initWithAttributes:attr];
   7.190 -        if (fmt == nil) {
   7.191 -            SDL_SetError ("Failed creating OpenGL pixel format");
   7.192 -            return NULL;
   7.193 -        }
   7.194 -
   7.195 -        context = [[NSOpenGLContext alloc] initWithFormat:fmt shareContext:nil];
   7.196 -
   7.197 -        [fmt release];
   7.198 -
   7.199 -        if (context == nil) {
   7.200 -            SDL_SetError ("Failed creating OpenGL context");
   7.201 -            return NULL;
   7.202 -        }
   7.203 -
   7.204 -        /*
   7.205 -         * Wisdom from Apple engineer in reference to UT2003's OpenGL performance:
   7.206 -         *  "You are blowing a couple of the internal OpenGL function caches. This
   7.207 -         *  appears to be happening in the VAO case.  You can tell OpenGL to up
   7.208 -         *  the cache size by issuing the following calls right after you create
   7.209 -         *  the OpenGL context.  The default cache size is 16."    --ryan.
   7.210 -         */
   7.211 -
   7.212 -        #ifndef GLI_ARRAY_FUNC_CACHE_MAX
   7.213 -        #define GLI_ARRAY_FUNC_CACHE_MAX 284
   7.214 -        #endif
   7.215 -
   7.216 -        #ifndef GLI_SUBMIT_FUNC_CACHE_MAX
   7.217 -        #define GLI_SUBMIT_FUNC_CACHE_MAX 280
   7.218 -        #endif
   7.219 -
   7.220 -        {
   7.221 -            GLint cache_max = 64;
   7.222 -            CGLContextObj ctx = [context CGLContextObj];
   7.223 -            CGLSetParameter (ctx, GLI_SUBMIT_FUNC_CACHE_MAX, &cache_max);
   7.224 -            CGLSetParameter (ctx, GLI_ARRAY_FUNC_CACHE_MAX, &cache_max);
   7.225 -        }
   7.226 -    }
   7.227 -    /* End Wisdom from Apple Engineer section. --ryan. */
   7.228 +    [pool release];
   7.229  
   7.230      if ( Cocoa_GL_MakeCurrent(_this, window, context) < 0 ) {
   7.231          Cocoa_GL_DeleteContext(_this, context);
   7.232 @@ -220,94 +226,107 @@
   7.233  int
   7.234  Cocoa_GL_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context)
   7.235  {
   7.236 -    @autoreleasepool {
   7.237 -        if (context) {
   7.238 -            SDL_WindowData *windowdata = (SDL_WindowData *)window->driverdata;
   7.239 -            NSOpenGLContext *nscontext = (NSOpenGLContext *)context;
   7.240 +    NSAutoreleasePool *pool;
   7.241  
   7.242 -            if (window->flags & SDL_WINDOW_SHOWN) {
   7.243 -    #ifndef FULLSCREEN_TOGGLEABLE
   7.244 -                if (window->flags & SDL_WINDOW_FULLSCREEN) {
   7.245 -                    [nscontext setFullScreen];
   7.246 -                } else
   7.247 -    #endif
   7.248 -                {
   7.249 -                    [nscontext setView:[windowdata->nswindow contentView]];
   7.250 -                    [nscontext update];
   7.251 -                }
   7.252 +    pool = [[NSAutoreleasePool alloc] init];
   7.253 +
   7.254 +    if (context) {
   7.255 +        SDL_WindowData *windowdata = (SDL_WindowData *)window->driverdata;
   7.256 +        NSOpenGLContext *nscontext = (NSOpenGLContext *)context;
   7.257 +
   7.258 +        if (window->flags & SDL_WINDOW_SHOWN) {
   7.259 +#ifndef FULLSCREEN_TOGGLEABLE
   7.260 +            if (window->flags & SDL_WINDOW_FULLSCREEN) {
   7.261 +                [nscontext setFullScreen];
   7.262 +            } else
   7.263 +#endif
   7.264 +            {
   7.265 +                [nscontext setView:[windowdata->nswindow contentView]];
   7.266 +                [nscontext update];
   7.267              }
   7.268 -            [nscontext makeCurrentContext];
   7.269 -        } else {
   7.270 -            [NSOpenGLContext clearCurrentContext];
   7.271          }
   7.272 +        [nscontext makeCurrentContext];
   7.273 +    } else {
   7.274 +        [NSOpenGLContext clearCurrentContext];
   7.275      }
   7.276  
   7.277 +    [pool release];
   7.278      return 0;
   7.279  }
   7.280  
   7.281  int
   7.282  Cocoa_GL_SetSwapInterval(_THIS, int interval)
   7.283  {
   7.284 +    NSAutoreleasePool *pool;
   7.285      NSOpenGLContext *nscontext;
   7.286      GLint value;
   7.287      int status;
   7.288  
   7.289 -    @autoreleasepool {
   7.290 -        nscontext = [NSOpenGLContext currentContext];
   7.291 -        if (nscontext != nil) {
   7.292 -            value = interval;
   7.293 -            [nscontext setValues:&value forParameter:NSOpenGLCPSwapInterval];
   7.294 -            status = 0;
   7.295 -        } else {
   7.296 -            SDL_SetError("No current OpenGL context");
   7.297 -            status = -1;
   7.298 -        }
   7.299 +    pool = [[NSAutoreleasePool alloc] init];
   7.300 +
   7.301 +    nscontext = [NSOpenGLContext currentContext];
   7.302 +    if (nscontext != nil) {
   7.303 +        value = interval;
   7.304 +        [nscontext setValues:&value forParameter:NSOpenGLCPSwapInterval];
   7.305 +        status = 0;
   7.306 +    } else {
   7.307 +        SDL_SetError("No current OpenGL context");
   7.308 +        status = -1;
   7.309      }
   7.310  
   7.311 +    [pool release];
   7.312      return status;
   7.313  }
   7.314  
   7.315  int
   7.316  Cocoa_GL_GetSwapInterval(_THIS)
   7.317  {
   7.318 +    NSAutoreleasePool *pool;
   7.319      NSOpenGLContext *nscontext;
   7.320      GLint value;
   7.321      int status = 0;
   7.322  
   7.323 -    @autoreleasepool {
   7.324 -        nscontext = [NSOpenGLContext currentContext];
   7.325 -        if (nscontext != nil) {
   7.326 -            [nscontext getValues:&value forParameter:NSOpenGLCPSwapInterval];
   7.327 -            status = (int)value;
   7.328 -        }
   7.329 +    pool = [[NSAutoreleasePool alloc] init];
   7.330 +
   7.331 +    nscontext = [NSOpenGLContext currentContext];
   7.332 +    if (nscontext != nil) {
   7.333 +        [nscontext getValues:&value forParameter:NSOpenGLCPSwapInterval];
   7.334 +        status = (int)value;
   7.335      }
   7.336  
   7.337 +    [pool release];
   7.338      return status;
   7.339  }
   7.340  
   7.341  void
   7.342  Cocoa_GL_SwapWindow(_THIS, SDL_Window * window)
   7.343  {
   7.344 +    NSAutoreleasePool *pool;
   7.345      NSOpenGLContext *nscontext;
   7.346  
   7.347 -    @autoreleasepool {
   7.348 -        /* FIXME: Do we need to get the context for the window? */
   7.349 -        nscontext = [NSOpenGLContext currentContext];
   7.350 -        if (nscontext != nil) {
   7.351 -            [nscontext flushBuffer];
   7.352 -        }
   7.353 +    pool = [[NSAutoreleasePool alloc] init];
   7.354 +
   7.355 +    /* FIXME: Do we need to get the context for the window? */
   7.356 +    nscontext = [NSOpenGLContext currentContext];
   7.357 +    if (nscontext != nil) {
   7.358 +        [nscontext flushBuffer];
   7.359      }
   7.360 +
   7.361 +    [pool release];
   7.362  }
   7.363  
   7.364  void
   7.365  Cocoa_GL_DeleteContext(_THIS, SDL_GLContext context)
   7.366  {
   7.367 +    NSAutoreleasePool *pool;
   7.368      NSOpenGLContext *nscontext = (NSOpenGLContext *)context;
   7.369  
   7.370 -    @autoreleasepool {
   7.371 -        [nscontext clearDrawable];
   7.372 -        [nscontext release];
   7.373 -    }
   7.374 +    pool = [[NSAutoreleasePool alloc] init];
   7.375 +
   7.376 +    [nscontext clearDrawable];
   7.377 +    [nscontext release];
   7.378 +
   7.379 +    [pool release];
   7.380  }
   7.381  
   7.382  #endif /* SDL_VIDEO_OPENGL_CGL */
     8.1 --- a/src/video/cocoa/SDL_cocoashape.m	Mon Feb 11 17:25:58 2013 -0800
     8.2 +++ b/src/video/cocoa/SDL_cocoashape.m	Mon Feb 11 17:39:52 2013 -0800
     8.3 @@ -74,7 +74,7 @@
     8.4      SDL_ShapeData* data = (SDL_ShapeData*)shaper->driverdata;
     8.5  	SDL_WindowData* windata = (SDL_WindowData*)shaper->window->driverdata;
     8.6  	SDL_CocoaClosure closure;
     8.7 -
     8.8 +	NSAutoreleasePool *pool = NULL;
     8.9      if(data->saved == SDL_TRUE) {
    8.10          [data->context restoreGraphicsState];
    8.11          data->saved = SDL_FALSE;
    8.12 @@ -88,13 +88,12 @@
    8.13      NSRectFill([[windata->nswindow contentView] frame]);
    8.14      data->shape = SDL_CalculateShapeTree(*shape_mode,shape);
    8.15  	
    8.16 -    @autoreleasepool {
    8.17 -        closure.view = [windata->nswindow contentView];
    8.18 -        closure.path = [[NSBezierPath bezierPath] autorelease];
    8.19 -        closure.window = shaper->window;
    8.20 -        SDL_TraverseShapeTree(data->shape,&ConvertRects,&closure);
    8.21 -        [closure.path addClip];
    8.22 -    }
    8.23 +	pool = [[NSAutoreleasePool alloc] init];
    8.24 +    closure.view = [windata->nswindow contentView];
    8.25 +    closure.path = [[NSBezierPath bezierPath] autorelease];
    8.26 +	closure.window = shaper->window;
    8.27 +    SDL_TraverseShapeTree(data->shape,&ConvertRects,&closure);
    8.28 +    [closure.path addClip];
    8.29  
    8.30      return 0;
    8.31  }
     9.1 --- a/src/video/cocoa/SDL_cocoavideo.m	Mon Feb 11 17:25:58 2013 -0800
     9.2 +++ b/src/video/cocoa/SDL_cocoavideo.m	Mon Feb 11 17:39:52 2013 -0800
     9.3 @@ -250,37 +250,39 @@
     9.4          }
     9.5      }
     9.6  
     9.7 -    @autoreleasepool {
     9.8 -        NSString *msg = [NSString stringWithFormat:
     9.9 -                @"Assertion failure at %s (%s:%d), triggered %u time%s:\n  '%s'",
    9.10 -                    data->function, data->filename, data->linenum,
    9.11 -                    data->trigger_count, (data->trigger_count == 1) ? "" : "s",
    9.12 -                    data->condition];
    9.13 +    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    9.14  
    9.15 -        NSLog(@"%@", msg);
    9.16 +    NSString *msg = [NSString stringWithFormat:
    9.17 +            @"Assertion failure at %s (%s:%d), triggered %u time%s:\n  '%s'",
    9.18 +                data->function, data->filename, data->linenum,
    9.19 +                data->trigger_count, (data->trigger_count == 1) ? "" : "s",
    9.20 +                data->condition];
    9.21  
    9.22 -        /*
    9.23 -         * !!! FIXME: this code needs to deal with fullscreen modes:
    9.24 -         * !!! FIXME:  reset to default desktop, runModal, reset to current?
    9.25 -         */
    9.26 +    NSLog(@"%@", msg);
    9.27  
    9.28 -        NSAlert* alert = [[NSAlert alloc] init];
    9.29 -        [alert setAlertStyle:NSCriticalAlertStyle];
    9.30 -        [alert setMessageText:msg];
    9.31 -        [alert addButtonWithTitle:@"Retry"];
    9.32 -        [alert addButtonWithTitle:@"Break"];
    9.33 -        [alert addButtonWithTitle:@"Abort"];
    9.34 -        [alert addButtonWithTitle:@"Ignore"];
    9.35 -        [alert addButtonWithTitle:@"Always Ignore"];
    9.36 -        const NSInteger clicked = [alert runModal];
    9.37 -        [alert release];
    9.38 +    /*
    9.39 +     * !!! FIXME: this code needs to deal with fullscreen modes:
    9.40 +     * !!! FIXME:  reset to default desktop, runModal, reset to current?
    9.41 +     */
    9.42  
    9.43 -        if (!initialized) {
    9.44 -            SDL_QuitSubSystem(SDL_INIT_VIDEO);
    9.45 -        }
    9.46 +    NSAlert* alert = [[NSAlert alloc] init];
    9.47 +    [alert setAlertStyle:NSCriticalAlertStyle];
    9.48 +    [alert setMessageText:msg];
    9.49 +    [alert addButtonWithTitle:@"Retry"];
    9.50 +    [alert addButtonWithTitle:@"Break"];
    9.51 +    [alert addButtonWithTitle:@"Abort"];
    9.52 +    [alert addButtonWithTitle:@"Ignore"];
    9.53 +    [alert addButtonWithTitle:@"Always Ignore"];
    9.54 +    const NSInteger clicked = [alert runModal];
    9.55 +    [alert release];
    9.56  
    9.57 -        return (SDL_assert_state) (clicked - NSAlertFirstButtonReturn);
    9.58 +    [pool release];
    9.59 +
    9.60 +    if (!initialized) {
    9.61 +        SDL_QuitSubSystem(SDL_INIT_VIDEO);
    9.62      }
    9.63 +
    9.64 +    return (SDL_assert_state) (clicked - NSAlertFirstButtonReturn);
    9.65  }
    9.66  
    9.67  #endif /* SDL_VIDEO_DRIVER_COCOA */
    10.1 --- a/src/video/cocoa/SDL_cocoawindow.m	Mon Feb 11 17:25:58 2013 -0800
    10.2 +++ b/src/video/cocoa/SDL_cocoawindow.m	Mon Feb 11 17:39:52 2013 -0800
    10.3 @@ -507,6 +507,7 @@
    10.4  static int
    10.5  SetupWindowData(_THIS, SDL_Window * window, NSWindow *nswindow, SDL_bool created)
    10.6  {
    10.7 +    NSAutoreleasePool *pool;
    10.8      SDL_VideoData *videodata = (SDL_VideoData *) _this->driverdata;
    10.9      SDL_WindowData *data;
   10.10  
   10.11 @@ -521,297 +522,313 @@
   10.12      data->created = created;
   10.13      data->videodata = videodata;
   10.14  
   10.15 -    @autoreleasepool {
   10.16 -        /* Create an event listener for the window */
   10.17 -        data->listener = [[Cocoa_WindowListener alloc] init];
   10.18 +    pool = [[NSAutoreleasePool alloc] init];
   10.19  
   10.20 -        /* Fill in the SDL window with the window data */
   10.21 -        {
   10.22 -            NSRect rect = [nswindow contentRectForFrameRect:[nswindow frame]];
   10.23 -            ConvertNSRect(&rect);
   10.24 -            window->x = (int)rect.origin.x;
   10.25 -            window->y = (int)rect.origin.y;
   10.26 -            window->w = (int)rect.size.width;
   10.27 -            window->h = (int)rect.size.height;
   10.28 +    /* Create an event listener for the window */
   10.29 +    data->listener = [[Cocoa_WindowListener alloc] init];
   10.30 +
   10.31 +    /* Fill in the SDL window with the window data */
   10.32 +    {
   10.33 +        NSRect rect = [nswindow contentRectForFrameRect:[nswindow frame]];
   10.34 +        ConvertNSRect(&rect);
   10.35 +        window->x = (int)rect.origin.x;
   10.36 +        window->y = (int)rect.origin.y;
   10.37 +        window->w = (int)rect.size.width;
   10.38 +        window->h = (int)rect.size.height;
   10.39 +    }
   10.40 +
   10.41 +    /* Set up the listener after we create the view */
   10.42 +    [data->listener listen:data];
   10.43 +
   10.44 +    if ([nswindow isVisible]) {
   10.45 +        window->flags |= SDL_WINDOW_SHOWN;
   10.46 +    } else {
   10.47 +        window->flags &= ~SDL_WINDOW_SHOWN;
   10.48 +    }
   10.49 +    {
   10.50 +        unsigned int style = [nswindow styleMask];
   10.51 +
   10.52 +        if (style == NSBorderlessWindowMask) {
   10.53 +            window->flags |= SDL_WINDOW_BORDERLESS;
   10.54 +        } else {
   10.55 +            window->flags &= ~SDL_WINDOW_BORDERLESS;
   10.56          }
   10.57 +        if (style & NSResizableWindowMask) {
   10.58 +            window->flags |= SDL_WINDOW_RESIZABLE;
   10.59 +        } else {
   10.60 +            window->flags &= ~SDL_WINDOW_RESIZABLE;
   10.61 +        }
   10.62 +    }
   10.63 +    /* isZoomed always returns true if the window is not resizable */
   10.64 +    if ((window->flags & SDL_WINDOW_RESIZABLE) && [nswindow isZoomed]) {
   10.65 +        window->flags |= SDL_WINDOW_MAXIMIZED;
   10.66 +    } else {
   10.67 +        window->flags &= ~SDL_WINDOW_MAXIMIZED;
   10.68 +    }
   10.69 +    if ([nswindow isMiniaturized]) {
   10.70 +        window->flags |= SDL_WINDOW_MINIMIZED;
   10.71 +    } else {
   10.72 +        window->flags &= ~SDL_WINDOW_MINIMIZED;
   10.73 +    }
   10.74 +    if ([nswindow isKeyWindow]) {
   10.75 +        window->flags |= SDL_WINDOW_INPUT_FOCUS;
   10.76 +        SDL_SetKeyboardFocus(data->window);
   10.77 +    }
   10.78  
   10.79 -        /* Set up the listener after we create the view */
   10.80 -        [data->listener listen:data];
   10.81 -
   10.82 -        if ([nswindow isVisible]) {
   10.83 -            window->flags |= SDL_WINDOW_SHOWN;
   10.84 -        } else {
   10.85 -            window->flags &= ~SDL_WINDOW_SHOWN;
   10.86 -        }
   10.87 -        {
   10.88 -            unsigned int style = [nswindow styleMask];
   10.89 -
   10.90 -            if (style == NSBorderlessWindowMask) {
   10.91 -                window->flags |= SDL_WINDOW_BORDERLESS;
   10.92 -            } else {
   10.93 -                window->flags &= ~SDL_WINDOW_BORDERLESS;
   10.94 -            }
   10.95 -            if (style & NSResizableWindowMask) {
   10.96 -                window->flags |= SDL_WINDOW_RESIZABLE;
   10.97 -            } else {
   10.98 -                window->flags &= ~SDL_WINDOW_RESIZABLE;
   10.99 -            }
  10.100 -        }
  10.101 -        /* isZoomed always returns true if the window is not resizable */
  10.102 -        if ((window->flags & SDL_WINDOW_RESIZABLE) && [nswindow isZoomed]) {
  10.103 -            window->flags |= SDL_WINDOW_MAXIMIZED;
  10.104 -        } else {
  10.105 -            window->flags &= ~SDL_WINDOW_MAXIMIZED;
  10.106 -        }
  10.107 -        if ([nswindow isMiniaturized]) {
  10.108 -            window->flags |= SDL_WINDOW_MINIMIZED;
  10.109 -        } else {
  10.110 -            window->flags &= ~SDL_WINDOW_MINIMIZED;
  10.111 -        }
  10.112 -        if ([nswindow isKeyWindow]) {
  10.113 -            window->flags |= SDL_WINDOW_INPUT_FOCUS;
  10.114 -            SDL_SetKeyboardFocus(data->window);
  10.115 -        }
  10.116 -
  10.117 -        /* All done! */
  10.118 -        window->driverdata = data;
  10.119 -        return 0;
  10.120 -    }
  10.121 +    /* All done! */
  10.122 +    [pool release];
  10.123 +    window->driverdata = data;
  10.124 +    return 0;
  10.125  }
  10.126  
  10.127  int
  10.128  Cocoa_CreateWindow(_THIS, SDL_Window * window)
  10.129  {
  10.130 -    @autoreleasepool {
  10.131 -        NSWindow *nswindow;
  10.132 -        SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
  10.133 -        NSRect rect;
  10.134 -        SDL_Rect bounds;
  10.135 -        unsigned int style;
  10.136 +    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
  10.137 +    NSWindow *nswindow;
  10.138 +    SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
  10.139 +    NSRect rect;
  10.140 +    SDL_Rect bounds;
  10.141 +    unsigned int style;
  10.142  
  10.143 -        Cocoa_GetDisplayBounds(_this, display, &bounds);
  10.144 -        rect.origin.x = window->x;
  10.145 -        rect.origin.y = window->y;
  10.146 -        rect.size.width = window->w;
  10.147 -        rect.size.height = window->h;
  10.148 -        ConvertNSRect(&rect);
  10.149 +    Cocoa_GetDisplayBounds(_this, display, &bounds);
  10.150 +    rect.origin.x = window->x;
  10.151 +    rect.origin.y = window->y;
  10.152 +    rect.size.width = window->w;
  10.153 +    rect.size.height = window->h;
  10.154 +    ConvertNSRect(&rect);
  10.155  
  10.156 -        style = GetWindowStyle(window);
  10.157 +    style = GetWindowStyle(window);
  10.158  
  10.159 -        /* Figure out which screen to place this window */
  10.160 -        NSArray *screens = [NSScreen screens];
  10.161 -        NSScreen *screen = nil;
  10.162 -        NSScreen *candidate;
  10.163 -        int i, count = [screens count];
  10.164 -        for (i = 0; i < count; ++i) {
  10.165 -            candidate = [screens objectAtIndex:i];
  10.166 -            NSRect screenRect = [candidate frame];
  10.167 -            if (rect.origin.x >= screenRect.origin.x &&
  10.168 -                rect.origin.x < screenRect.origin.x + screenRect.size.width &&
  10.169 -                rect.origin.y >= screenRect.origin.y &&
  10.170 -                rect.origin.y < screenRect.origin.y + screenRect.size.height) {
  10.171 -                screen = candidate;
  10.172 -                rect.origin.x -= screenRect.origin.x;
  10.173 -                rect.origin.y -= screenRect.origin.y;
  10.174 -            }
  10.175 +    /* Figure out which screen to place this window */
  10.176 +    NSArray *screens = [NSScreen screens];
  10.177 +    NSScreen *screen = nil;
  10.178 +    NSScreen *candidate;
  10.179 +    int i, count = [screens count];
  10.180 +    for (i = 0; i < count; ++i) {
  10.181 +        candidate = [screens objectAtIndex:i];
  10.182 +        NSRect screenRect = [candidate frame];
  10.183 +        if (rect.origin.x >= screenRect.origin.x &&
  10.184 +            rect.origin.x < screenRect.origin.x + screenRect.size.width &&
  10.185 +            rect.origin.y >= screenRect.origin.y &&
  10.186 +            rect.origin.y < screenRect.origin.y + screenRect.size.height) {
  10.187 +            screen = candidate;
  10.188 +            rect.origin.x -= screenRect.origin.x;
  10.189 +            rect.origin.y -= screenRect.origin.y;
  10.190          }
  10.191 -        nswindow = [[SDLWindow alloc] initWithContentRect:rect styleMask:style backing:NSBackingStoreBuffered defer:YES screen:screen];
  10.192 +    }
  10.193 +    nswindow = [[SDLWindow alloc] initWithContentRect:rect styleMask:style backing:NSBackingStoreBuffered defer:YES screen:screen];
  10.194  
  10.195 -        // Create a default view for this window
  10.196 -        rect = [nswindow contentRectForFrameRect:[nswindow frame]];
  10.197 -        NSView *contentView = [[SDLView alloc] initWithFrame:rect];
  10.198 -        [nswindow setContentView: contentView];
  10.199 -        [contentView release];
  10.200 +    // Create a default view for this window
  10.201 +    rect = [nswindow contentRectForFrameRect:[nswindow frame]];
  10.202 +    NSView *contentView = [[SDLView alloc] initWithFrame:rect];
  10.203 +    [nswindow setContentView: contentView];
  10.204 +    [contentView release];
  10.205  
  10.206 -        if (SetupWindowData(_this, window, nswindow, SDL_TRUE) < 0) {
  10.207 -            [nswindow release];
  10.208 -            return -1;
  10.209 -        }
  10.210 -        return 0;
  10.211 +    [pool release];
  10.212 +
  10.213 +    if (SetupWindowData(_this, window, nswindow, SDL_TRUE) < 0) {
  10.214 +        [nswindow release];
  10.215 +        return -1;
  10.216      }
  10.217 +    return 0;
  10.218  }
  10.219  
  10.220  int
  10.221  Cocoa_CreateWindowFrom(_THIS, SDL_Window * window, const void *data)
  10.222  {
  10.223 +    NSAutoreleasePool *pool;
  10.224      NSWindow *nswindow = (NSWindow *) data;
  10.225      NSString *title;
  10.226  
  10.227 -    @autoreleasepool {
  10.228 -        /* Query the title from the existing window */
  10.229 -        title = [nswindow title];
  10.230 -        if (title) {
  10.231 -            window->title = SDL_strdup([title UTF8String]);
  10.232 -        }
  10.233 +    pool = [[NSAutoreleasePool alloc] init];
  10.234 +
  10.235 +    /* Query the title from the existing window */
  10.236 +    title = [nswindow title];
  10.237 +    if (title) {
  10.238 +        window->title = SDL_strdup([title UTF8String]);
  10.239      }
  10.240  
  10.241 +    [pool release];
  10.242 +
  10.243      return SetupWindowData(_this, window, nswindow, SDL_FALSE);
  10.244  }
  10.245  
  10.246  void
  10.247  Cocoa_SetWindowTitle(_THIS, SDL_Window * window)
  10.248  {
  10.249 -    @autoreleasepool {
  10.250 -        NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
  10.251 -        NSString *string;
  10.252 +    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
  10.253 +    NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
  10.254 +    NSString *string;
  10.255  
  10.256 -        if(window->title) {
  10.257 -            string = [[NSString alloc] initWithUTF8String:window->title];
  10.258 -        } else {
  10.259 -            string = [[NSString alloc] init];
  10.260 -        }
  10.261 -        [nswindow setTitle:string];
  10.262 -        [string release];
  10.263 +    if(window->title) {
  10.264 +        string = [[NSString alloc] initWithUTF8String:window->title];
  10.265 +    } else {
  10.266 +        string = [[NSString alloc] init];
  10.267      }
  10.268 +    [nswindow setTitle:string];
  10.269 +    [string release];
  10.270 +
  10.271 +    [pool release];
  10.272  }
  10.273  
  10.274  void
  10.275  Cocoa_SetWindowIcon(_THIS, SDL_Window * window, SDL_Surface * icon)
  10.276  {
  10.277 -    @autoreleasepool {
  10.278 -        NSImage *nsimage = Cocoa_CreateImage(icon);
  10.279 +    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
  10.280 +    NSImage *nsimage = Cocoa_CreateImage(icon);
  10.281  
  10.282 -        if (nsimage) {
  10.283 -            [NSApp setApplicationIconImage:nsimage];
  10.284 -        }
  10.285 +    if (nsimage) {
  10.286 +        [NSApp setApplicationIconImage:nsimage];
  10.287      }
  10.288 +
  10.289 +    [pool release];
  10.290  }
  10.291  
  10.292  void
  10.293  Cocoa_SetWindowPosition(_THIS, SDL_Window * window)
  10.294  {
  10.295 -    @autoreleasepool {
  10.296 -        NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
  10.297 -        NSRect rect;
  10.298 -        Uint32 moveHack;
  10.299 +    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
  10.300 +    NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
  10.301 +    NSRect rect;
  10.302 +    Uint32 moveHack;
  10.303  
  10.304 -        rect.origin.x = window->x;
  10.305 -        rect.origin.y = window->y;
  10.306 -        rect.size.width = window->w;
  10.307 -        rect.size.height = window->h;
  10.308 -        ConvertNSRect(&rect);
  10.309 +    rect.origin.x = window->x;
  10.310 +    rect.origin.y = window->y;
  10.311 +    rect.size.width = window->w;
  10.312 +    rect.size.height = window->h;
  10.313 +    ConvertNSRect(&rect);
  10.314  
  10.315 -        moveHack = s_moveHack;
  10.316 -        s_moveHack = 0;
  10.317 -        [nswindow setFrameOrigin:rect.origin];
  10.318 -        s_moveHack = moveHack;
  10.319 +    moveHack = s_moveHack;
  10.320 +    s_moveHack = 0;
  10.321 +    [nswindow setFrameOrigin:rect.origin];
  10.322 +    s_moveHack = moveHack;
  10.323  
  10.324 -        if (window == _this->current_glwin) {
  10.325 -            [((NSOpenGLContext *) _this->current_glctx) update];
  10.326 -        }
  10.327 +    if (window == _this->current_glwin) {
  10.328 +        [((NSOpenGLContext *) _this->current_glctx) update];
  10.329      }
  10.330 +
  10.331 +    [pool release];
  10.332  }
  10.333  
  10.334  void
  10.335  Cocoa_SetWindowSize(_THIS, SDL_Window * window)
  10.336  {
  10.337 -    @autoreleasepool {
  10.338 -        SDL_WindowData *windata = (SDL_WindowData *) window->driverdata;
  10.339 -        NSWindow *nswindow = windata->nswindow;
  10.340 -        NSSize size;
  10.341 +    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
  10.342 +    SDL_WindowData *windata = (SDL_WindowData *) window->driverdata;
  10.343 +    NSWindow *nswindow = windata->nswindow;
  10.344 +    NSSize size;
  10.345  
  10.346 -        size.width = window->w;
  10.347 -        size.height = window->h;
  10.348 -        [nswindow setContentSize:size];
  10.349 +    size.width = window->w;
  10.350 +    size.height = window->h;
  10.351 +    [nswindow setContentSize:size];
  10.352  
  10.353 -        if (window == _this->current_glwin) {
  10.354 -            [((NSOpenGLContext *) _this->current_glctx) update];
  10.355 -        }
  10.356 +    if (window == _this->current_glwin) {
  10.357 +        [((NSOpenGLContext *) _this->current_glctx) update];
  10.358      }
  10.359 +
  10.360 +    [pool release];
  10.361  }
  10.362  
  10.363  void
  10.364  Cocoa_SetWindowMinimumSize(_THIS, SDL_Window * window)
  10.365  {
  10.366 -    @autoreleasepool {
  10.367 -        SDL_WindowData *windata = (SDL_WindowData *) window->driverdata;
  10.368 -            
  10.369 -        NSSize minSize;
  10.370 -        minSize.width = window->min_w;
  10.371 -        minSize.height = window->min_h;
  10.372 -            
  10.373 -        [windata->nswindow setContentMinSize:minSize];
  10.374 -    }
  10.375 +    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
  10.376 +    SDL_WindowData *windata = (SDL_WindowData *) window->driverdata;
  10.377 +        
  10.378 +    NSSize minSize;
  10.379 +    minSize.width = window->min_w;
  10.380 +    minSize.height = window->min_h;
  10.381 +        
  10.382 +    [windata->nswindow setContentMinSize:minSize];
  10.383 +    
  10.384 +    [pool release];
  10.385  }
  10.386  
  10.387  void
  10.388  Cocoa_SetWindowMaximumSize(_THIS, SDL_Window * window)
  10.389  {
  10.390 -    @autoreleasepool {
  10.391 -        SDL_WindowData *windata = (SDL_WindowData *) window->driverdata;
  10.392 -            
  10.393 -        NSSize maxSize;
  10.394 -        maxSize.width = window->max_w;
  10.395 -        maxSize.height = window->max_h;
  10.396 -            
  10.397 -        [windata->nswindow setContentMaxSize:maxSize];
  10.398 -    }
  10.399 +    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
  10.400 +    SDL_WindowData *windata = (SDL_WindowData *) window->driverdata;
  10.401 +        
  10.402 +    NSSize maxSize;
  10.403 +    maxSize.width = window->max_w;
  10.404 +    maxSize.height = window->max_h;
  10.405 +        
  10.406 +    [windata->nswindow setContentMaxSize:maxSize];
  10.407 +    
  10.408 +    [pool release];
  10.409  }
  10.410  
  10.411  void
  10.412  Cocoa_ShowWindow(_THIS, SDL_Window * window)
  10.413  {
  10.414 -    @autoreleasepool {
  10.415 -        NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
  10.416 +    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
  10.417 +    NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
  10.418  
  10.419 -        if (![nswindow isMiniaturized]) {
  10.420 -            [nswindow makeKeyAndOrderFront:nil];
  10.421 -        }
  10.422 +    if (![nswindow isMiniaturized]) {
  10.423 +        [nswindow makeKeyAndOrderFront:nil];
  10.424      }
  10.425 +    [pool release];
  10.426  }
  10.427  
  10.428  void
  10.429  Cocoa_HideWindow(_THIS, SDL_Window * window)
  10.430  {
  10.431 -    @autoreleasepool {
  10.432 -        NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
  10.433 -        [nswindow orderOut:nil];
  10.434 -    }
  10.435 +    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
  10.436 +    NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
  10.437 +
  10.438 +    [nswindow orderOut:nil];
  10.439 +    [pool release];
  10.440  }
  10.441  
  10.442  void
  10.443  Cocoa_RaiseWindow(_THIS, SDL_Window * window)
  10.444  {
  10.445 -    @autoreleasepool {
  10.446 -        NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
  10.447 -        [nswindow makeKeyAndOrderFront:nil];
  10.448 -    }
  10.449 +    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
  10.450 +    NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
  10.451 +
  10.452 +    [nswindow makeKeyAndOrderFront:nil];
  10.453 +    [pool release];
  10.454  }
  10.455  
  10.456  void
  10.457  Cocoa_MaximizeWindow(_THIS, SDL_Window * window)
  10.458  {
  10.459 -    @autoreleasepool {
  10.460 -        NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
  10.461 -        [nswindow zoom:nil];
  10.462 +    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
  10.463 +    NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
  10.464  
  10.465 -        if (window == _this->current_glwin) {
  10.466 -            [((NSOpenGLContext *) _this->current_glctx) update];
  10.467 -        }
  10.468 +    [nswindow zoom:nil];
  10.469 +
  10.470 +    if (window == _this->current_glwin) {
  10.471 +        [((NSOpenGLContext *) _this->current_glctx) update];
  10.472      }
  10.473 +
  10.474 +    [pool release];
  10.475  }
  10.476  
  10.477  void
  10.478  Cocoa_MinimizeWindow(_THIS, SDL_Window * window)
  10.479  {
  10.480 -    @autoreleasepool {
  10.481 -        NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
  10.482 -        [nswindow miniaturize:nil];
  10.483 -    }
  10.484 +    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
  10.485 +    NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
  10.486 +
  10.487 +    [nswindow miniaturize:nil];
  10.488 +    [pool release];
  10.489  }
  10.490  
  10.491  void
  10.492  Cocoa_RestoreWindow(_THIS, SDL_Window * window)
  10.493  {
  10.494 -    @autoreleasepool {
  10.495 -        NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
  10.496 +    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
  10.497 +    NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
  10.498  
  10.499 -        if ([nswindow isMiniaturized]) {
  10.500 -            [nswindow deminiaturize:nil];
  10.501 -        } else if ((window->flags & SDL_WINDOW_RESIZABLE) && [nswindow isZoomed]) {
  10.502 -            [nswindow zoom:nil];
  10.503 -        }
  10.504 +    if ([nswindow isMiniaturized]) {
  10.505 +        [nswindow deminiaturize:nil];
  10.506 +    } else if ((window->flags & SDL_WINDOW_RESIZABLE) && [nswindow isZoomed]) {
  10.507 +        [nswindow zoom:nil];
  10.508      }
  10.509 +    [pool release];
  10.510  }
  10.511  
  10.512  static NSWindow *
  10.513 @@ -837,95 +854,96 @@
  10.514  {
  10.515      /* this message arrived in 10.6. You're out of luck on older OSes. */
  10.516  #if MAC_OS_X_VERSION_MAX_ALLOWED >= 1060
  10.517 -    @autoreleasepool {
  10.518 -        NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
  10.519 -        if ([nswindow respondsToSelector:@selector(setStyleMask:)]) {
  10.520 -            [nswindow setStyleMask:GetWindowStyle(window)];
  10.521 -            if (bordered) {
  10.522 -                Cocoa_SetWindowTitle(_this, window);  // this got blanked out.
  10.523 -            }
  10.524 +    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
  10.525 +    NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
  10.526 +    if ([nswindow respondsToSelector:@selector(setStyleMask:)]) {
  10.527 +        [nswindow setStyleMask:GetWindowStyle(window)];
  10.528 +        if (bordered) {
  10.529 +            Cocoa_SetWindowTitle(_this, window);  // this got blanked out.
  10.530          }
  10.531      }
  10.532 +    [pool release];
  10.533  #endif
  10.534  }
  10.535  
  10.536  void
  10.537  Cocoa_SetWindowFullscreen(_THIS, SDL_Window * window, SDL_VideoDisplay * display, SDL_bool fullscreen)
  10.538  {
  10.539 -    @autoreleasepool {
  10.540 -        SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
  10.541 -        NSWindow *nswindow = data->nswindow;
  10.542 -        NSRect rect;
  10.543 +    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
  10.544 +    SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
  10.545 +    NSWindow *nswindow = data->nswindow;
  10.546 +    NSRect rect;
  10.547  
  10.548 -        /* The view responder chain gets messed with during setStyleMask */
  10.549 -        if ([[nswindow contentView] nextResponder] == data->listener) {
  10.550 -            [[nswindow contentView] setNextResponder:nil];
  10.551 +    /* The view responder chain gets messed with during setStyleMask */
  10.552 +    if ([[nswindow contentView] nextResponder] == data->listener) {
  10.553 +        [[nswindow contentView] setNextResponder:nil];
  10.554 +    }
  10.555 +
  10.556 +    if (fullscreen) {
  10.557 +        SDL_Rect bounds;
  10.558 +
  10.559 +        Cocoa_GetDisplayBounds(_this, display, &bounds);
  10.560 +        rect.origin.x = bounds.x;
  10.561 +        rect.origin.y = bounds.y;
  10.562 +        rect.size.width = bounds.w;
  10.563 +        rect.size.height = bounds.h;
  10.564 +        ConvertNSRect(&rect);
  10.565 +
  10.566 +        /* Hack to fix origin on Mac OS X 10.4 */
  10.567 +        NSRect screenRect = [[nswindow screen] frame];
  10.568 +        if (screenRect.size.height >= 1.0f) {
  10.569 +            rect.origin.y += (screenRect.size.height - rect.size.height);
  10.570          }
  10.571  
  10.572 -        if (fullscreen) {
  10.573 -            SDL_Rect bounds;
  10.574 +        if ([nswindow respondsToSelector: @selector(setStyleMask:)]) {
  10.575 +            [nswindow performSelector: @selector(setStyleMask:) withObject: (id)NSBorderlessWindowMask];
  10.576 +        } else {
  10.577 +            nswindow = Cocoa_RebuildWindow(data, nswindow, NSBorderlessWindowMask);
  10.578 +        }
  10.579 +    } else {
  10.580 +        rect.origin.x = window->windowed.x;
  10.581 +        rect.origin.y = window->windowed.y;
  10.582 +        rect.size.width = window->windowed.w;
  10.583 +        rect.size.height = window->windowed.h;
  10.584 +        ConvertNSRect(&rect);
  10.585  
  10.586 -            Cocoa_GetDisplayBounds(_this, display, &bounds);
  10.587 -            rect.origin.x = bounds.x;
  10.588 -            rect.origin.y = bounds.y;
  10.589 -            rect.size.width = bounds.w;
  10.590 -            rect.size.height = bounds.h;
  10.591 -            ConvertNSRect(&rect);
  10.592 -
  10.593 -            /* Hack to fix origin on Mac OS X 10.4 */
  10.594 -            NSRect screenRect = [[nswindow screen] frame];
  10.595 -            if (screenRect.size.height >= 1.0f) {
  10.596 -                rect.origin.y += (screenRect.size.height - rect.size.height);
  10.597 -            }
  10.598 -
  10.599 -            if ([nswindow respondsToSelector: @selector(setStyleMask:)]) {
  10.600 -                [nswindow performSelector: @selector(setStyleMask:) withObject: (id)NSBorderlessWindowMask];
  10.601 -            } else {
  10.602 -                nswindow = Cocoa_RebuildWindow(data, nswindow, NSBorderlessWindowMask);
  10.603 -            }
  10.604 +        if ([nswindow respondsToSelector: @selector(setStyleMask:)]) {
  10.605 +            [nswindow performSelector: @selector(setStyleMask:) withObject: (id)(uintptr_t)GetWindowStyle(window)];
  10.606          } else {
  10.607 -            rect.origin.x = window->windowed.x;
  10.608 -            rect.origin.y = window->windowed.y;
  10.609 -            rect.size.width = window->windowed.w;
  10.610 -            rect.size.height = window->windowed.h;
  10.611 -            ConvertNSRect(&rect);
  10.612 -
  10.613 -            if ([nswindow respondsToSelector: @selector(setStyleMask:)]) {
  10.614 -                [nswindow performSelector: @selector(setStyleMask:) withObject: (id)(uintptr_t)GetWindowStyle(window)];
  10.615 -            } else {
  10.616 -                nswindow = Cocoa_RebuildWindow(data, nswindow, GetWindowStyle(window));
  10.617 -            }
  10.618 -        }
  10.619 -
  10.620 -        /* The view responder chain gets messed with during setStyleMask */
  10.621 -        if ([[nswindow contentView] nextResponder] != data->listener) {
  10.622 -            [[nswindow contentView] setNextResponder:data->listener];
  10.623 -        }
  10.624 -
  10.625 -        s_moveHack = 0;
  10.626 -        [nswindow setFrameOrigin:rect.origin];
  10.627 -        [nswindow setContentSize:rect.size];
  10.628 -        s_moveHack = SDL_GetTicks();
  10.629 -
  10.630 -        /* When the window style changes the title is cleared */
  10.631 -        if (!fullscreen) {
  10.632 -            Cocoa_SetWindowTitle(_this, window);
  10.633 -        }
  10.634 -
  10.635 -    #ifdef FULLSCREEN_TOGGLEABLE
  10.636 -        if (SDL_ShouldAllowTopmost() && fullscreen) {
  10.637 -            /* OpenGL is rendering to the window, so make it visible! */
  10.638 -            [nswindow setLevel:CGShieldingWindowLevel()];
  10.639 -        } else {
  10.640 -            [nswindow setLevel:kCGNormalWindowLevel];
  10.641 -        }
  10.642 -    #endif
  10.643 -        [nswindow makeKeyAndOrderFront:nil];
  10.644 -
  10.645 -        if (window == _this->current_glwin) {
  10.646 -            [((NSOpenGLContext *) _this->current_glctx) update];
  10.647 +            nswindow = Cocoa_RebuildWindow(data, nswindow, GetWindowStyle(window));
  10.648          }
  10.649      }
  10.650 +
  10.651 +    /* The view responder chain gets messed with during setStyleMask */
  10.652 +    if ([[nswindow contentView] nextResponder] != data->listener) {
  10.653 +        [[nswindow contentView] setNextResponder:data->listener];
  10.654 +    }
  10.655 +
  10.656 +    s_moveHack = 0;
  10.657 +    [nswindow setFrameOrigin:rect.origin];
  10.658 +    [nswindow setContentSize:rect.size];
  10.659 +    s_moveHack = SDL_GetTicks();
  10.660 +
  10.661 +    /* When the window style changes the title is cleared */
  10.662 +    if (!fullscreen) {
  10.663 +        Cocoa_SetWindowTitle(_this, window);
  10.664 +    }
  10.665 +
  10.666 +#ifdef FULLSCREEN_TOGGLEABLE
  10.667 +    if (SDL_ShouldAllowTopmost() && fullscreen) {
  10.668 +        /* OpenGL is rendering to the window, so make it visible! */
  10.669 +        [nswindow setLevel:CGShieldingWindowLevel()];
  10.670 +    } else {
  10.671 +        [nswindow setLevel:kCGNormalWindowLevel];
  10.672 +    }
  10.673 +#endif
  10.674 +    [nswindow makeKeyAndOrderFront:nil];
  10.675 +
  10.676 +    if (window == _this->current_glwin) {
  10.677 +        [((NSOpenGLContext *) _this->current_glctx) update];
  10.678 +    }
  10.679 +
  10.680 +    [pool release];
  10.681  }
  10.682  
  10.683  int
  10.684 @@ -1009,18 +1027,18 @@
  10.685  void
  10.686  Cocoa_DestroyWindow(_THIS, SDL_Window * window)
  10.687  {
  10.688 -    @autoreleasepool {
  10.689 -        SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
  10.690 +    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
  10.691 +    SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
  10.692  
  10.693 -        if (data) {
  10.694 -            [data->listener close];
  10.695 -            [data->listener release];
  10.696 -            if (data->created) {
  10.697 -                [data->nswindow close];
  10.698 -            }
  10.699 -            SDL_free(data);
  10.700 +    if (data) {
  10.701 +        [data->listener close];
  10.702 +        [data->listener release];
  10.703 +        if (data->created) {
  10.704 +            [data->nswindow close];
  10.705          }
  10.706 +        SDL_free(data);
  10.707      }
  10.708 +    [pool release];
  10.709  }
  10.710  
  10.711  SDL_bool
    11.1 --- a/test/automated/rwops/TestSupportRWops_Cocoa.m	Mon Feb 11 17:25:58 2013 -0800
    11.2 +++ b/test/automated/rwops/TestSupportRWops_Cocoa.m	Mon Feb 11 17:39:52 2013 -0800
    11.3 @@ -21,23 +21,30 @@
    11.4      FILE* fp = NULL;
    11.5  
    11.6  	// If the file mode is writable, skip all the bundle stuff because generally the bundle is read-only.
    11.7 -	if (strcmp("r", mode) && strcmp("rb", mode)) {
    11.8 +	if(strcmp("r", mode) && strcmp("rb", mode))
    11.9 +	{
   11.10  		return fopen(file, mode);
   11.11  	}
   11.12  	
   11.13 -	@autoreleasepool {
   11.14 -        NSFileManager* file_manager = [NSFileManager defaultManager];
   11.15 -        NSString* resource_path = [[NSBundle mainBundle] resourcePath];
   11.16 +	NSAutoreleasePool* autorelease_pool = [[NSAutoreleasePool alloc] init];
   11.17  
   11.18 -        NSString* ns_string_file_component = [file_manager stringWithFileSystemRepresentation:file length:strlen(file)];
   11.19  
   11.20 -        NSString* full_path_with_file_to_try = [resource_path stringByAppendingPathComponent:ns_string_file_component];
   11.21 -        if ([file_manager fileExistsAtPath:full_path_with_file_to_try]) {
   11.22 -            fp = fopen([full_path_with_file_to_try fileSystemRepresentation], mode);
   11.23 -        } else {
   11.24 -            fp = fopen(file, mode);
   11.25 -        }
   11.26 -    }
   11.27 +	NSFileManager* file_manager = [NSFileManager defaultManager];
   11.28 +	NSString* resource_path = [[NSBundle mainBundle] resourcePath];
   11.29 +
   11.30 +	NSString* ns_string_file_component = [file_manager stringWithFileSystemRepresentation:file length:strlen(file)];
   11.31 +
   11.32 +	NSString* full_path_with_file_to_try = [resource_path stringByAppendingPathComponent:ns_string_file_component];
   11.33 +	if([file_manager fileExistsAtPath:full_path_with_file_to_try])
   11.34 +	{
   11.35 +		fp = fopen([full_path_with_file_to_try fileSystemRepresentation], mode);
   11.36 +	}
   11.37 +	else
   11.38 +	{
   11.39 +		fp = fopen(file, mode);
   11.40 +	}
   11.41 +
   11.42 +	[autorelease_pool drain];
   11.43  
   11.44  	return fp;
   11.45  }
   11.46 @@ -46,14 +53,16 @@
   11.47  {
   11.48      FILE* fp = NULL;
   11.49  	
   11.50 -	@autoreleasepool {
   11.51 -        NSFileManager* file_manager = [NSFileManager defaultManager];
   11.52 -        NSString* ns_string_file_component = [file_manager stringWithFileSystemRepresentation:file length:strlen(file)];
   11.53 -        NSString* full_path_with_file_to_try = [NSTemporaryDirectory() stringByAppendingPathComponent:ns_string_file_component];
   11.54 +	NSAutoreleasePool* autorelease_pool = [[NSAutoreleasePool alloc] init];
   11.55 +	
   11.56 +	NSFileManager* file_manager = [NSFileManager defaultManager];
   11.57 +	NSString* ns_string_file_component = [file_manager stringWithFileSystemRepresentation:file length:strlen(file)];
   11.58 +	NSString* full_path_with_file_to_try = [NSTemporaryDirectory() stringByAppendingPathComponent:ns_string_file_component];
   11.59  
   11.60 -        fp = fopen([full_path_with_file_to_try fileSystemRepresentation], mode);
   11.61 -    }
   11.62 -    
   11.63 +	fp = fopen([full_path_with_file_to_try fileSystemRepresentation], mode);
   11.64 +	
   11.65 +	[autorelease_pool drain];
   11.66 +	
   11.67  	return fp;
   11.68  }
   11.69  
   11.70 @@ -66,14 +75,15 @@
   11.71  {
   11.72  	SDL_RWops* rw = NULL;
   11.73  
   11.74 -	@autoreleasepool {
   11.75 -        NSFileManager* file_manager = [NSFileManager defaultManager];
   11.76 -        NSString* ns_string_file_component = [file_manager stringWithFileSystemRepresentation:file length:strlen(file)];
   11.77 -        NSString* full_path_with_file_to_try = [NSTemporaryDirectory() stringByAppendingPathComponent:ns_string_file_component];
   11.78 -        
   11.79 -        rw = SDL_RWFromFile( [full_path_with_file_to_try fileSystemRepresentation], mode );
   11.80 -    }
   11.81 -    
   11.82 +	NSAutoreleasePool* autorelease_pool = [[NSAutoreleasePool alloc] init];
   11.83 +	
   11.84 +	NSFileManager* file_manager = [NSFileManager defaultManager];
   11.85 +	NSString* ns_string_file_component = [file_manager stringWithFileSystemRepresentation:file length:strlen(file)];
   11.86 +	NSString* full_path_with_file_to_try = [NSTemporaryDirectory() stringByAppendingPathComponent:ns_string_file_component];
   11.87 +	
   11.88 +	rw = SDL_RWFromFile( [full_path_with_file_to_try fileSystemRepresentation], mode );
   11.89 +
   11.90 +	[autorelease_pool drain];
   11.91  	return rw;
   11.92  }
   11.93