Backed out use of @autorelease keyword for now, since it's not supported by older Xcode versions.
authorSam Lantinga
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  
    1.13 -        NSString* ns_string_file_component = [file_manager stringWithFileSystemRepresentation:file length:strlen(file)];
    1.14 +	NSFileManager* file_manager = [NSFileManager defaultManager];
    1.15 +	NSString* resource_path = [[NSBundle mainBundle] resourcePath];
    1.16 +
    1.17 +	NSString* ns_string_file_component = [file_manager stringWithFileSystemRepresentation:file length:strlen(file)];
    1.18  
    1.19 -        NSString* full_path_with_file_to_try = [resource_path stringByAppendingPathComponent:ns_string_file_component];
    1.20 -        if([file_manager fileExistsAtPath:full_path_with_file_to_try])
    1.21 -        {
    1.22 -            fp = fopen([full_path_with_file_to_try fileSystemRepresentation], mode);
    1.23 -        }
    1.24 -        else
    1.25 -        {
    1.26 -            fp = fopen(file, mode);
    1.27 -        }
    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 +    pasteboard = [NSPasteboard generalPasteboard];
    2.47 +    available = [pasteboard availableTypeFromArray: [NSArray arrayWithObject:format]];
    2.48 +    if ([available isEqualToString:format]) {
    2.49 +        NSString* string;
    2.50 +        const char *utf8;
    2.51  
    2.52 -            string = [pasteboard stringForType:format];
    2.53 -            if (string == nil) {
    2.54 -                utf8 = "";
    2.55 -            } else {
    2.56 -                utf8 = [string UTF8String];
    2.57 -            }
    2.58 -            text = SDL_strdup(utf8);
    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 +    NSAlert* alert = [[NSAlert alloc] init];
    5.12  
    5.13 -        if (messageboxdata->flags & SDL_MESSAGEBOX_ERROR) {
    5.14 -            [alert setAlertStyle:NSCriticalAlertStyle];
    5.15 -        } else if (messageboxdata->flags & SDL_MESSAGEBOX_WARNING) {
    5.16 -            [alert setAlertStyle:NSWarningAlertStyle];
    5.17 -        } else {
    5.18 -            [alert setAlertStyle:NSInformationalAlertStyle];
    5.19 -        }
    5.20 +    if (messageboxdata->flags & SDL_MESSAGEBOX_ERROR) {
    5.21 +        [alert setAlertStyle:NSCriticalAlertStyle];
    5.22 +    } else if (messageboxdata->flags & SDL_MESSAGEBOX_WARNING) {
    5.23 +        [alert setAlertStyle:NSWarningAlertStyle];
    5.24 +    } else {
    5.25 +        [alert setAlertStyle:NSInformationalAlertStyle];
    5.26 +    }
    5.27  
    5.28 -        [alert setMessageText:[NSString stringWithUTF8String:messageboxdata->title]];
    5.29 -        [alert setInformativeText:[NSString stringWithUTF8String:messageboxdata->message]];
    5.30 +    [alert setMessageText:[NSString stringWithUTF8String:messageboxdata->title]];
    5.31 +    [alert setInformativeText:[NSString stringWithUTF8String:messageboxdata->message]];
    5.32  
    5.33 -        const SDL_MessageBoxButtonData *buttons = messageboxdata->buttons;
    5.34 -        int i;
    5.35 -        for (i = 0; i < messageboxdata->numbuttons; ++i) {
    5.36 -            NSButton *button = [alert addButtonWithTitle:[NSString stringWithUTF8String:buttons[i].text]];
    5.37 -            if (buttons[i].flags & SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT) {
    5.38 -                [button setKeyEquivalent:@"\r"];
    5.39 -            } else if (buttons[i].flags & SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT) {
    5.40 -                [button setKeyEquivalent:@"\033"];
    5.41 -            } else {
    5.42 -                [button setKeyEquivalent:@""];
    5.43 -            }
    5.44 +    const SDL_MessageBoxButtonData *buttons = messageboxdata->buttons;
    5.45 +    int i;
    5.46 +    for (i = 0; i < messageboxdata->numbuttons; ++i) {
    5.47 +        NSButton *button = [alert addButtonWithTitle:[NSString stringWithUTF8String:buttons[i].text]];
    5.48 +        if (buttons[i].flags & SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT) {
    5.49 +            [button setKeyEquivalent:@"\r"];
    5.50 +        } else if (buttons[i].flags & SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT) {
    5.51 +            [button setKeyEquivalent:@"\033"];
    5.52 +        } else {
    5.53 +            [button setKeyEquivalent:@""];
    5.54          }
    5.55 +    }
    5.56  
    5.57 -        NSInteger clicked = [alert runModal];
    5.58 -        clicked -= NSAlertFirstButtonReturn;
    5.59 -        *buttonid = buttons[clicked].buttonid;
    5.60 -        [alert release];
    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 -        }
    6.54 +    nsimage = Cocoa_CreateImage(surface);
    6.55 +    if (nsimage) {
    6.56 +        nscursor = [[NSCursor alloc] initWithImage: nsimage hotSpot: NSMakePoint(hot_x, hot_y)];
    6.57 +    }
    6.58  
    6.59 -        if (nscursor) {
    6.60 -            cursor = SDL_calloc(1, sizeof(*cursor));
    6.61 -            if (cursor) {
    6.62 -                cursor->driverdata = nscursor;
    6.63 -            }
    6.64 +    if (nscursor) {
    6.65 +        cursor = SDL_calloc(1, sizeof(*cursor));
    6.66 +        if (cursor) {
    6.67 +            cursor->driverdata = nscursor;
    6.68          }
    6.69 -        
    6.70 -        return cursor;
    6.71      }
    6.72 +
    6.73 +    [pool release];
    6.74 +
    6.75 +    return cursor;
    6.76  }
    6.77  
    6.78  static SDL_Cursor *
    6.79  Cocoa_CreateSystemCursor(SDL_SystemCursor id)
    6.80  {
    6.81 -    @autoreleasepool {
    6.82 -        NSCursor *nscursor = NULL;
    6.83 -        SDL_Cursor *cursor = NULL;
    6.84 +    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    6.85 +    NSCursor *nscursor = NULL;
    6.86 +    SDL_Cursor *cursor = NULL;
    6.87  
    6.88 -        switch(id)
    6.89 -        {
    6.90 -        case SDL_SYSTEM_CURSOR_ARROW:
    6.91 -            nscursor = [NSCursor arrowCursor];
    6.92 -            break;
    6.93 -        case SDL_SYSTEM_CURSOR_IBEAM:
    6.94 -            nscursor = [NSCursor IBeamCursor];
    6.95 -            break;
    6.96 -        case SDL_SYSTEM_CURSOR_WAIT:
    6.97 -            nscursor = [NSCursor arrowCursor];
    6.98 -            break;
    6.99 -        case SDL_SYSTEM_CURSOR_CROSSHAIR:
   6.100 -            nscursor = [NSCursor crosshairCursor];
   6.101 -            break;
   6.102 -        case SDL_SYSTEM_CURSOR_WAITARROW:
   6.103 -            nscursor = [NSCursor arrowCursor];
   6.104 -            break;
   6.105 -        case SDL_SYSTEM_CURSOR_SIZENWSE:
   6.106 -        case SDL_SYSTEM_CURSOR_SIZENESW:
   6.107 -            nscursor = [NSCursor closedHandCursor];
   6.108 -            break;
   6.109 -        case SDL_SYSTEM_CURSOR_SIZEWE:
   6.110 -            nscursor = [NSCursor resizeLeftRightCursor];
   6.111 -            break;
   6.112 -        case SDL_SYSTEM_CURSOR_SIZENS:
   6.113 -            nscursor = [NSCursor resizeUpDownCursor];
   6.114 -            break;
   6.115 -        case SDL_SYSTEM_CURSOR_SIZEALL:
   6.116 -            nscursor = [NSCursor closedHandCursor];
   6.117 -            break;
   6.118 -        case SDL_SYSTEM_CURSOR_NO:
   6.119 -            nscursor = [NSCursor operationNotAllowedCursor];
   6.120 -            break;
   6.121 -        case SDL_SYSTEM_CURSOR_HAND:
   6.122 -            nscursor = [NSCursor pointingHandCursor];
   6.123 -            break;
   6.124 -        default:
   6.125 -            SDL_assert(!"Unknown system cursor");
   6.126 -            return NULL;
   6.127 +    switch(id)
   6.128 +    {
   6.129 +    case SDL_SYSTEM_CURSOR_ARROW:
   6.130 +        nscursor = [NSCursor arrowCursor];
   6.131 +        break;
   6.132 +    case SDL_SYSTEM_CURSOR_IBEAM:
   6.133 +        nscursor = [NSCursor IBeamCursor];
   6.134 +        break;
   6.135 +    case SDL_SYSTEM_CURSOR_WAIT:
   6.136 +        nscursor = [NSCursor arrowCursor];
   6.137 +        break;
   6.138 +    case SDL_SYSTEM_CURSOR_CROSSHAIR:
   6.139 +        nscursor = [NSCursor crosshairCursor];
   6.140 +        break;
   6.141 +    case SDL_SYSTEM_CURSOR_WAITARROW:
   6.142 +        nscursor = [NSCursor arrowCursor];
   6.143 +        break;
   6.144 +    case SDL_SYSTEM_CURSOR_SIZENWSE:
   6.145 +    case SDL_SYSTEM_CURSOR_SIZENESW:
   6.146 +        nscursor = [NSCursor closedHandCursor];
   6.147 +        break;
   6.148 +    case SDL_SYSTEM_CURSOR_SIZEWE:
   6.149 +        nscursor = [NSCursor resizeLeftRightCursor];
   6.150 +        break;
   6.151 +    case SDL_SYSTEM_CURSOR_SIZENS:
   6.152 +        nscursor = [NSCursor resizeUpDownCursor];
   6.153 +        break;
   6.154 +    case SDL_SYSTEM_CURSOR_SIZEALL:
   6.155 +        nscursor = [NSCursor closedHandCursor];
   6.156 +        break;
   6.157 +    case SDL_SYSTEM_CURSOR_NO:
   6.158 +        nscursor = [NSCursor operationNotAllowedCursor];
   6.159 +        break;
   6.160 +    case SDL_SYSTEM_CURSOR_HAND:
   6.161 +        nscursor = [NSCursor pointingHandCursor];
   6.162 +        break;
   6.163 +    default:
   6.164 +        SDL_assert(!"Unknown system cursor");
   6.165 +        return NULL;
   6.166 +    }
   6.167 +
   6.168 +    if (nscursor) {
   6.169 +        cursor = SDL_calloc(1, sizeof(*cursor));
   6.170 +        if (cursor) {
   6.171 +            // We'll free it later, so retain it here
   6.172 +            [nscursor retain];
   6.173 +            cursor->driverdata = nscursor;
   6.174          }
   6.175 +    }
   6.176  
   6.177 -        if (nscursor) {
   6.178 -            cursor = SDL_calloc(1, sizeof(*cursor));
   6.179 -            if (cursor) {
   6.180 -                // We'll free it later, so retain it here
   6.181 -                [nscursor retain];
   6.182 -                cursor->driverdata = nscursor;
   6.183 -            }
   6.184 -        }
   6.185 -            
   6.186 -        return cursor;
   6.187 -    }
   6.188 +    [pool release];
   6.189 +
   6.190 +    return cursor;
   6.191  }
   6.192  
   6.193  static void
   6.194  Cocoa_FreeCursor(SDL_Cursor * cursor)
   6.195  {
   6.196 -    @autoreleasepool {
   6.197 -        NSCursor *nscursor = (NSCursor *)cursor->driverdata;
   6.198 +    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
   6.199 +    NSCursor *nscursor = (NSCursor *)cursor->driverdata;
   6.200  
   6.201 -        [nscursor release];
   6.202 -        SDL_free(cursor);
   6.203 -    }
   6.204 +    [nscursor release];
   6.205 +    SDL_free(cursor);
   6.206 +
   6.207 +    [pool release];
   6.208  }
   6.209  
   6.210  static int
   6.211  Cocoa_ShowCursor(SDL_Cursor * cursor)
   6.212  {
   6.213 -    @autoreleasepool {
   6.214 -        if (cursor) {
   6.215 -            NSCursor *nscursor = (NSCursor *)cursor->driverdata;
   6.216 +    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
   6.217 +
   6.218 +    if (cursor) {
   6.219 +        NSCursor *nscursor = (NSCursor *)cursor->driverdata;
   6.220  
   6.221 -            [nscursor set];
   6.222 -            [NSCursor unhide];
   6.223 -        } else {
   6.224 -            [NSCursor hide];
   6.225 -        }
   6.226 +        [nscursor set];
   6.227 +        [NSCursor unhide];
   6.228 +    } else {
   6.229 +        [NSCursor hide];
   6.230      }
   6.231  
   6.232 +    [pool release];
   6.233 +
   6.234      return 0;
   6.235  }
   6.236  
     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 +    }
    7.43 +#endif
    7.44 +
    7.45 +    attr[i++] = NSOpenGLPFAColorSize;
    7.46 +    attr[i++] = SDL_BYTESPERPIXEL(display->current_mode.format)*8;
    7.47 +
    7.48 +    attr[i++] = NSOpenGLPFADepthSize;
    7.49 +    attr[i++] = _this->gl_config.depth_size;
    7.50 +
    7.51 +    if (_this->gl_config.double_buffer) {
    7.52 +        attr[i++] = NSOpenGLPFADoubleBuffer;
    7.53 +    }
    7.54 +
    7.55 +    if (_this->gl_config.stereo) {
    7.56 +        attr[i++] = NSOpenGLPFAStereo;
    7.57 +    }
    7.58 +
    7.59 +    if (_this->gl_config.stencil_size) {
    7.60 +        attr[i++] = NSOpenGLPFAStencilSize;
    7.61 +        attr[i++] = _this->gl_config.stencil_size;
    7.62 +    }
    7.63 +
    7.64 +    if ((_this->gl_config.accum_red_size +
    7.65 +         _this->gl_config.accum_green_size +
    7.66 +         _this->gl_config.accum_blue_size +
    7.67 +         _this->gl_config.accum_alpha_size) > 0) {
    7.68 +        attr[i++] = NSOpenGLPFAAccumSize;
    7.69 +        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.70 +    }
    7.71 +
    7.72 +    if (_this->gl_config.multisamplebuffers) {
    7.73 +        attr[i++] = NSOpenGLPFASampleBuffers;
    7.74 +        attr[i++] = _this->gl_config.multisamplebuffers;
    7.75 +    }
    7.76  
    7.77 -    #ifndef FULLSCREEN_TOGGLEABLE
    7.78 -        if (window->flags & SDL_WINDOW_FULLSCREEN) {
    7.79 -            attr[i++] = NSOpenGLPFAFullScreen;
    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 -
   7.131 -        attr[i++] = NSOpenGLPFADepthSize;
   7.132 -        attr[i++] = _this->gl_config.depth_size;
   7.133 -
   7.134 -        if (_this->gl_config.double_buffer) {
   7.135 -            attr[i++] = NSOpenGLPFADoubleBuffer;
   7.136 -        }
   7.137 -
   7.138 -        if (_this->gl_config.stereo) {
   7.139 -            attr[i++] = NSOpenGLPFAStereo;
   7.140 -        }
   7.141 -
   7.142 -        if (_this->gl_config.stencil_size) {
   7.143 -            attr[i++] = NSOpenGLPFAStencilSize;
   7.144 -            attr[i++] = _this->gl_config.stencil_size;
   7.145 -        }
   7.146 -
   7.147 -        if ((_this->gl_config.accum_red_size +
   7.148 -             _this->gl_config.accum_green_size +
   7.149 -             _this->gl_config.accum_blue_size +
   7.150 -             _this->gl_config.accum_alpha_size) > 0) {
   7.151 -            attr[i++] = NSOpenGLPFAAccumSize;
   7.152 -            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.153 -        }
   7.154 -
   7.155 -        if (_this->gl_config.multisamplebuffers) {
   7.156 -            attr[i++] = NSOpenGLPFASampleBuffers;
   7.157 -            attr[i++] = _this->gl_config.multisamplebuffers;
   7.158 -        }
   7.159 -
   7.160 -        if (_this->gl_config.multisamplesamples) {
   7.161 -            attr[i++] = NSOpenGLPFASamples;
   7.162 -            attr[i++] = _this->gl_config.multisamplesamples;
   7.163 -            attr[i++] = NSOpenGLPFANoRecovery;
   7.164 -        }
   7.165 +    #ifndef GLI_SUBMIT_FUNC_CACHE_MAX
   7.166 +    #define GLI_SUBMIT_FUNC_CACHE_MAX 280
   7.167 +    #endif
   7.168  
   7.169 -        if (_this->gl_config.accelerated >= 0) {
   7.170 -            if (_this->gl_config.accelerated) {
   7.171 -                attr[i++] = NSOpenGLPFAAccelerated;
   7.172 -            } else {
   7.173 -                attr[i++] = NSOpenGLPFARendererID;
   7.174 -                attr[i++] = kCGLRendererGenericFloatID;
   7.175 -            }
   7.176 -        }
   7.177 -
   7.178 -        attr[i++] = NSOpenGLPFAScreenMask;
   7.179 -        attr[i++] = CGDisplayIDToOpenGLDisplayMask(displaydata->display);
   7.180 -        attr[i] = 0;
   7.181 -
   7.182 -        fmt = [[NSOpenGLPixelFormat alloc] initWithAttributes:attr];
   7.183 -        if (fmt == nil) {
   7.184 -            SDL_SetError ("Failed creating OpenGL pixel format");
   7.185 -            return NULL;
   7.186 -        }
   7.187 -
   7.188 -        context = [[NSOpenGLContext alloc] initWithFormat:fmt shareContext:nil];
   7.189 -
   7.190 -        [fmt release];
   7.191 +    {
   7.192 +        GLint cache_max = 64;
   7.193 +        CGLContextObj ctx = [context CGLContextObj];
   7.194 +        CGLSetParameter (ctx, GLI_SUBMIT_FUNC_CACHE_MAX, &cache_max);
   7.195 +        CGLSetParameter (ctx, GLI_ARRAY_FUNC_CACHE_MAX, &cache_max);
   7.196 +    }
   7.197  
   7.198 -        if (context == nil) {
   7.199 -            SDL_SetError ("Failed creating OpenGL context");
   7.200 -            return NULL;
   7.201 -        }
   7.202 -
   7.203 -        /*
   7.204 -         * Wisdom from Apple engineer in reference to UT2003's OpenGL performance:
   7.205 -         *  "You are blowing a couple of the internal OpenGL function caches. This
   7.206 -         *  appears to be happening in the VAO case.  You can tell OpenGL to up
   7.207 -         *  the cache size by issuing the following calls right after you create
   7.208 -         *  the OpenGL context.  The default cache size is 16."    --ryan.
   7.209 -         */
   7.210 +    /* End Wisdom from Apple Engineer section. --ryan. */
   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 +    pool = [[NSAutoreleasePool alloc] init];
   7.243 +
   7.244 +    if (context) {
   7.245 +        SDL_WindowData *windowdata = (SDL_WindowData *)window->driverdata;
   7.246 +        NSOpenGLContext *nscontext = (NSOpenGLContext *)context;
   7.247  
   7.248 -            if (window->flags & SDL_WINDOW_SHOWN) {
   7.249 -    #ifndef FULLSCREEN_TOGGLEABLE
   7.250 -                if (window->flags & SDL_WINDOW_FULLSCREEN) {
   7.251 -                    [nscontext setFullScreen];
   7.252 -                } else
   7.253 -    #endif
   7.254 -                {
   7.255 -                    [nscontext setView:[windowdata->nswindow contentView]];
   7.256 -                    [nscontext update];
   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 +    /*
    9.29 +     * !!! FIXME: this code needs to deal with fullscreen modes:
    9.30 +     * !!! FIXME:  reset to default desktop, runModal, reset to current?
    9.31 +     */
    9.32  
    9.33 -        NSAlert* alert = [[NSAlert alloc] init];
    9.34 -        [alert setAlertStyle:NSCriticalAlertStyle];
    9.35 -        [alert setMessageText:msg];
    9.36 -        [alert addButtonWithTitle:@"Retry"];
    9.37 -        [alert addButtonWithTitle:@"Break"];
    9.38 -        [alert addButtonWithTitle:@"Abort"];
    9.39 -        [alert addButtonWithTitle:@"Ignore"];
    9.40 -        [alert addButtonWithTitle:@"Always Ignore"];
    9.41 -        const NSInteger clicked = [alert runModal];
    9.42 -        [alert release];
    9.43 +    NSAlert* alert = [[NSAlert alloc] init];
    9.44 +    [alert setAlertStyle:NSCriticalAlertStyle];
    9.45 +    [alert setMessageText:msg];
    9.46 +    [alert addButtonWithTitle:@"Retry"];
    9.47 +    [alert addButtonWithTitle:@"Break"];
    9.48 +    [alert addButtonWithTitle:@"Abort"];
    9.49 +    [alert addButtonWithTitle:@"Ignore"];
    9.50 +    [alert addButtonWithTitle:@"Always Ignore"];
    9.51 +    const NSInteger clicked = [alert runModal];
    9.52 +    [alert release];
    9.53  
    9.54 -        if (!initialized) {
    9.55 -            SDL_QuitSubSystem(SDL_INIT_VIDEO);
    9.56 -        }
    9.57 +    [pool release];
    9.58  
    9.59 -        return (SDL_assert_state) (clicked - NSAlertFirstButtonReturn);
    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 +    /* Create an event listener for the window */
   10.21 +    data->listener = [[Cocoa_WindowListener alloc] init];
   10.22  
   10.23 -        /* Fill in the SDL window with the window data */
   10.24 -        {
   10.25 -            NSRect rect = [nswindow contentRectForFrameRect:[nswindow frame]];
   10.26 -            ConvertNSRect(&rect);
   10.27 -            window->x = (int)rect.origin.x;
   10.28 -            window->y = (int)rect.origin.y;
   10.29 -            window->w = (int)rect.size.width;
   10.30 -            window->h = (int)rect.size.height;
   10.31 -        }
   10.32 +    /* Fill in the SDL window with the window data */
   10.33 +    {
   10.34 +        NSRect rect = [nswindow contentRectForFrameRect:[nswindow frame]];
   10.35 +        ConvertNSRect(&rect);
   10.36 +        window->x = (int)rect.origin.x;
   10.37 +        window->y = (int)rect.origin.y;
   10.38 +        window->w = (int)rect.size.width;
   10.39 +        window->h = (int)rect.size.height;
   10.40 +    }
   10.41  
   10.42 -        /* Set up the listener after we create the view */
   10.43 -        [data->listener listen:data];
   10.44 +    /* Set up the listener after we create the view */
   10.45 +    [data->listener listen:data];
   10.46  
   10.47 -        if ([nswindow isVisible]) {
   10.48 -            window->flags |= SDL_WINDOW_SHOWN;
   10.49 -        } else {
   10.50 -            window->flags &= ~SDL_WINDOW_SHOWN;
   10.51 -        }
   10.52 -        {
   10.53 -            unsigned int style = [nswindow styleMask];
   10.54 +    if ([nswindow isVisible]) {
   10.55 +        window->flags |= SDL_WINDOW_SHOWN;
   10.56 +    } else {
   10.57 +        window->flags &= ~SDL_WINDOW_SHOWN;
   10.58 +    }
   10.59 +    {
   10.60 +        unsigned int style = [nswindow styleMask];
   10.61  
   10.62 -            if (style == NSBorderlessWindowMask) {
   10.63 -                window->flags |= SDL_WINDOW_BORDERLESS;
   10.64 -            } else {
   10.65 -                window->flags &= ~SDL_WINDOW_BORDERLESS;
   10.66 -            }
   10.67 -            if (style & NSResizableWindowMask) {
   10.68 -                window->flags |= SDL_WINDOW_RESIZABLE;
   10.69 -            } else {
   10.70 -                window->flags &= ~SDL_WINDOW_RESIZABLE;
   10.71 -            }
   10.72 +        if (style == NSBorderlessWindowMask) {
   10.73 +            window->flags |= SDL_WINDOW_BORDERLESS;
   10.74 +        } else {
   10.75 +            window->flags &= ~SDL_WINDOW_BORDERLESS;
   10.76          }
   10.77 -        /* isZoomed always returns true if the window is not resizable */
   10.78 -        if ((window->flags & SDL_WINDOW_RESIZABLE) && [nswindow isZoomed]) {
   10.79 -            window->flags |= SDL_WINDOW_MAXIMIZED;
   10.80 +        if (style & NSResizableWindowMask) {
   10.81 +            window->flags |= SDL_WINDOW_RESIZABLE;
   10.82          } else {
   10.83 -            window->flags &= ~SDL_WINDOW_MAXIMIZED;
   10.84 -        }
   10.85 -        if ([nswindow isMiniaturized]) {
   10.86 -            window->flags |= SDL_WINDOW_MINIMIZED;
   10.87 -        } else {
   10.88 -            window->flags &= ~SDL_WINDOW_MINIMIZED;
   10.89 +            window->flags &= ~SDL_WINDOW_RESIZABLE;
   10.90          }
   10.91 -        if ([nswindow isKeyWindow]) {
   10.92 -            window->flags |= SDL_WINDOW_INPUT_FOCUS;
   10.93 -            SDL_SetKeyboardFocus(data->window);
   10.94 -        }
   10.95 +    }
   10.96 +    /* isZoomed always returns true if the window is not resizable */
   10.97 +    if ((window->flags & SDL_WINDOW_RESIZABLE) && [nswindow isZoomed]) {
   10.98 +        window->flags |= SDL_WINDOW_MAXIMIZED;
   10.99 +    } else {
  10.100 +        window->flags &= ~SDL_WINDOW_MAXIMIZED;
  10.101 +    }
  10.102 +    if ([nswindow isMiniaturized]) {
  10.103 +        window->flags |= SDL_WINDOW_MINIMIZED;
  10.104 +    } else {
  10.105 +        window->flags &= ~SDL_WINDOW_MINIMIZED;
  10.106 +    }
  10.107 +    if ([nswindow isKeyWindow]) {
  10.108 +        window->flags |= SDL_WINDOW_INPUT_FOCUS;
  10.109 +        SDL_SetKeyboardFocus(data->window);
  10.110 +    }
  10.111  
  10.112 -        /* All done! */
  10.113 -        window->driverdata = data;
  10.114 -        return 0;
  10.115 -    }
  10.116 +    /* All done! */
  10.117 +    [pool release];
  10.118 +    window->driverdata = data;
  10.119 +    return 0;
  10.120  }
  10.121  
  10.122  int
  10.123  Cocoa_CreateWindow(_THIS, SDL_Window * window)
  10.124  {
  10.125 -    @autoreleasepool {
  10.126 -        NSWindow *nswindow;
  10.127 -        SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
  10.128 -        NSRect rect;
  10.129 -        SDL_Rect bounds;
  10.130 -        unsigned int style;
  10.131 +    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
  10.132 +    NSWindow *nswindow;
  10.133 +    SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
  10.134 +    NSRect rect;
  10.135 +    SDL_Rect bounds;
  10.136 +    unsigned int style;
  10.137  
  10.138 -        Cocoa_GetDisplayBounds(_this, display, &bounds);
  10.139 -        rect.origin.x = window->x;
  10.140 -        rect.origin.y = window->y;
  10.141 -        rect.size.width = window->w;
  10.142 -        rect.size.height = window->h;
  10.143 -        ConvertNSRect(&rect);
  10.144 +    Cocoa_GetDisplayBounds(_this, display, &bounds);
  10.145 +    rect.origin.x = window->x;
  10.146 +    rect.origin.y = window->y;
  10.147 +    rect.size.width = window->w;
  10.148 +    rect.size.height = window->h;
  10.149 +    ConvertNSRect(&rect);
  10.150  
  10.151 -        style = GetWindowStyle(window);
  10.152 +    style = GetWindowStyle(window);
  10.153  
  10.154 -        /* Figure out which screen to place this window */
  10.155 -        NSArray *screens = [NSScreen screens];
  10.156 -        NSScreen *screen = nil;
  10.157 -        NSScreen *candidate;
  10.158 -        int i, count = [screens count];
  10.159 -        for (i = 0; i < count; ++i) {
  10.160 -            candidate = [screens objectAtIndex:i];
  10.161 -            NSRect screenRect = [candidate frame];
  10.162 -            if (rect.origin.x >= screenRect.origin.x &&
  10.163 -                rect.origin.x < screenRect.origin.x + screenRect.size.width &&
  10.164 -                rect.origin.y >= screenRect.origin.y &&
  10.165 -                rect.origin.y < screenRect.origin.y + screenRect.size.height) {
  10.166 -                screen = candidate;
  10.167 -                rect.origin.x -= screenRect.origin.x;
  10.168 -                rect.origin.y -= screenRect.origin.y;
  10.169 -            }
  10.170 +    /* Figure out which screen to place this window */
  10.171 +    NSArray *screens = [NSScreen screens];
  10.172 +    NSScreen *screen = nil;
  10.173 +    NSScreen *candidate;
  10.174 +    int i, count = [screens count];
  10.175 +    for (i = 0; i < count; ++i) {
  10.176 +        candidate = [screens objectAtIndex:i];
  10.177 +        NSRect screenRect = [candidate frame];
  10.178 +        if (rect.origin.x >= screenRect.origin.x &&
  10.179 +            rect.origin.x < screenRect.origin.x + screenRect.size.width &&
  10.180 +            rect.origin.y >= screenRect.origin.y &&
  10.181 +            rect.origin.y < screenRect.origin.y + screenRect.size.height) {
  10.182 +            screen = candidate;
  10.183 +            rect.origin.x -= screenRect.origin.x;
  10.184 +            rect.origin.y -= screenRect.origin.y;
  10.185          }
  10.186 -        nswindow = [[SDLWindow alloc] initWithContentRect:rect styleMask:style backing:NSBackingStoreBuffered defer:YES screen:screen];
  10.187 +    }
  10.188 +    nswindow = [[SDLWindow alloc] initWithContentRect:rect styleMask:style backing:NSBackingStoreBuffered defer:YES screen:screen];
  10.189  
  10.190 -        // Create a default view for this window
  10.191 -        rect = [nswindow contentRectForFrameRect:[nswindow frame]];
  10.192 -        NSView *contentView = [[SDLView alloc] initWithFrame:rect];
  10.193 -        [nswindow setContentView: contentView];
  10.194 -        [contentView release];
  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  
  10.201 -        if (SetupWindowData(_this, window, nswindow, SDL_TRUE) < 0) {
  10.202 -            [nswindow release];
  10.203 -            return -1;
  10.204 -        }
  10.205 -        return 0;
  10.206 +    [pool release];
  10.207 +
  10.208 +    if (SetupWindowData(_this, window, nswindow, SDL_TRUE) < 0) {
  10.209 +        [nswindow release];
  10.210 +        return -1;
  10.211      }
  10.212 +    return 0;
  10.213  }
  10.214  
  10.215  int
  10.216  Cocoa_CreateWindowFrom(_THIS, SDL_Window * window, const void *data)
  10.217  {
  10.218 +    NSAutoreleasePool *pool;
  10.219      NSWindow *nswindow = (NSWindow *) data;
  10.220      NSString *title;
  10.221  
  10.222 -    @autoreleasepool {
  10.223 -        /* Query the title from the existing window */
  10.224 -        title = [nswindow title];
  10.225 -        if (title) {
  10.226 -            window->title = SDL_strdup([title UTF8String]);
  10.227 -        }
  10.228 +    pool = [[NSAutoreleasePool alloc] init];
  10.229 +
  10.230 +    /* Query the title from the existing window */
  10.231 +    title = [nswindow title];
  10.232 +    if (title) {
  10.233 +        window->title = SDL_strdup([title UTF8String]);
  10.234      }
  10.235  
  10.236 +    [pool release];
  10.237 +
  10.238      return SetupWindowData(_this, window, nswindow, SDL_FALSE);
  10.239  }
  10.240  
  10.241  void
  10.242  Cocoa_SetWindowTitle(_THIS, SDL_Window * window)
  10.243  {
  10.244 -    @autoreleasepool {
  10.245 -        NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
  10.246 -        NSString *string;
  10.247 +    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
  10.248 +    NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
  10.249 +    NSString *string;
  10.250  
  10.251 -        if(window->title) {
  10.252 -            string = [[NSString alloc] initWithUTF8String:window->title];
  10.253 -        } else {
  10.254 -            string = [[NSString alloc] init];
  10.255 -        }
  10.256 -        [nswindow setTitle:string];
  10.257 -        [string release];
  10.258 +    if(window->title) {
  10.259 +        string = [[NSString alloc] initWithUTF8String:window->title];
  10.260 +    } else {
  10.261 +        string = [[NSString alloc] init];
  10.262      }
  10.263 +    [nswindow setTitle:string];
  10.264 +    [string release];
  10.265 +
  10.266 +    [pool release];
  10.267  }
  10.268  
  10.269  void
  10.270  Cocoa_SetWindowIcon(_THIS, SDL_Window * window, SDL_Surface * icon)
  10.271  {
  10.272 -    @autoreleasepool {
  10.273 -        NSImage *nsimage = Cocoa_CreateImage(icon);
  10.274 +    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
  10.275 +    NSImage *nsimage = Cocoa_CreateImage(icon);
  10.276  
  10.277 -        if (nsimage) {
  10.278 -            [NSApp setApplicationIconImage:nsimage];
  10.279 -        }
  10.280 +    if (nsimage) {
  10.281 +        [NSApp setApplicationIconImage:nsimage];
  10.282      }
  10.283 +
  10.284 +    [pool release];
  10.285  }
  10.286  
  10.287  void
  10.288  Cocoa_SetWindowPosition(_THIS, SDL_Window * window)
  10.289  {
  10.290 -    @autoreleasepool {
  10.291 -        NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
  10.292 -        NSRect rect;
  10.293 -        Uint32 moveHack;
  10.294 +    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
  10.295 +    NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
  10.296 +    NSRect rect;
  10.297 +    Uint32 moveHack;
  10.298 +
  10.299 +    rect.origin.x = window->x;
  10.300 +    rect.origin.y = window->y;
  10.301 +    rect.size.width = window->w;
  10.302 +    rect.size.height = window->h;
  10.303 +    ConvertNSRect(&rect);
  10.304  
  10.305 -        rect.origin.x = window->x;
  10.306 -        rect.origin.y = window->y;
  10.307 -        rect.size.width = window->w;
  10.308 -        rect.size.height = window->h;
  10.309 -        ConvertNSRect(&rect);
  10.310 +    moveHack = s_moveHack;
  10.311 +    s_moveHack = 0;
  10.312 +    [nswindow setFrameOrigin:rect.origin];
  10.313 +    s_moveHack = moveHack;
  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 +    if (window == _this->current_glwin) {
  10.320 +        [((NSOpenGLContext *) _this->current_glctx) update];
  10.321 +    }
  10.322  
  10.323 -        if (window == _this->current_glwin) {
  10.324 -            [((NSOpenGLContext *) _this->current_glctx) update];
  10.325 -        }
  10.326 -    }
  10.327 +    [pool release];
  10.328  }
  10.329  
  10.330  void
  10.331  Cocoa_SetWindowSize(_THIS, SDL_Window * window)
  10.332  {
  10.333 -    @autoreleasepool {
  10.334 -        SDL_WindowData *windata = (SDL_WindowData *) window->driverdata;
  10.335 -        NSWindow *nswindow = windata->nswindow;
  10.336 -        NSSize size;
  10.337 +    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
  10.338 +    SDL_WindowData *windata = (SDL_WindowData *) window->driverdata;
  10.339 +    NSWindow *nswindow = windata->nswindow;
  10.340 +    NSSize size;
  10.341  
  10.342 -        size.width = window->w;
  10.343 -        size.height = window->h;
  10.344 -        [nswindow setContentSize:size];
  10.345 +    size.width = window->w;
  10.346 +    size.height = window->h;
  10.347 +    [nswindow setContentSize:size];
  10.348  
  10.349 -        if (window == _this->current_glwin) {
  10.350 -            [((NSOpenGLContext *) _this->current_glctx) update];
  10.351 -        }
  10.352 +    if (window == _this->current_glwin) {
  10.353 +        [((NSOpenGLContext *) _this->current_glctx) update];
  10.354      }
  10.355 +
  10.356 +    [pool release];
  10.357  }
  10.358  
  10.359  void
  10.360  Cocoa_SetWindowMinimumSize(_THIS, SDL_Window * window)
  10.361  {
  10.362 -    @autoreleasepool {
  10.363 -        SDL_WindowData *windata = (SDL_WindowData *) window->driverdata;
  10.364 -            
  10.365 -        NSSize minSize;
  10.366 -        minSize.width = window->min_w;
  10.367 -        minSize.height = window->min_h;
  10.368 -            
  10.369 -        [windata->nswindow setContentMinSize:minSize];
  10.370 -    }
  10.371 +    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
  10.372 +    SDL_WindowData *windata = (SDL_WindowData *) window->driverdata;
  10.373 +        
  10.374 +    NSSize minSize;
  10.375 +    minSize.width = window->min_w;
  10.376 +    minSize.height = window->min_h;
  10.377 +        
  10.378 +    [windata->nswindow setContentMinSize:minSize];
  10.379 +    
  10.380 +    [pool release];
  10.381  }
  10.382  
  10.383  void
  10.384  Cocoa_SetWindowMaximumSize(_THIS, SDL_Window * window)
  10.385  {
  10.386 -    @autoreleasepool {
  10.387 -        SDL_WindowData *windata = (SDL_WindowData *) window->driverdata;
  10.388 -            
  10.389 -        NSSize maxSize;
  10.390 -        maxSize.width = window->max_w;
  10.391 -        maxSize.height = window->max_h;
  10.392 -            
  10.393 -        [windata->nswindow setContentMaxSize:maxSize];
  10.394 -    }
  10.395 +    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
  10.396 +    SDL_WindowData *windata = (SDL_WindowData *) window->driverdata;
  10.397 +        
  10.398 +    NSSize maxSize;
  10.399 +    maxSize.width = window->max_w;
  10.400 +    maxSize.height = window->max_h;
  10.401 +        
  10.402 +    [windata->nswindow setContentMaxSize:maxSize];
  10.403 +    
  10.404 +    [pool release];
  10.405  }
  10.406  
  10.407  void
  10.408  Cocoa_ShowWindow(_THIS, SDL_Window * window)
  10.409  {
  10.410 -    @autoreleasepool {
  10.411 -        NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
  10.412 +    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
  10.413 +    NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
  10.414  
  10.415 -        if (![nswindow isMiniaturized]) {
  10.416 -            [nswindow makeKeyAndOrderFront:nil];
  10.417 -        }
  10.418 +    if (![nswindow isMiniaturized]) {
  10.419 +        [nswindow makeKeyAndOrderFront:nil];
  10.420      }
  10.421 +    [pool release];
  10.422  }
  10.423  
  10.424  void
  10.425  Cocoa_HideWindow(_THIS, SDL_Window * window)
  10.426  {
  10.427 -    @autoreleasepool {
  10.428 -        NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
  10.429 -        [nswindow orderOut:nil];
  10.430 -    }
  10.431 +    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
  10.432 +    NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
  10.433 +
  10.434 +    [nswindow orderOut:nil];
  10.435 +    [pool release];
  10.436  }
  10.437  
  10.438  void
  10.439  Cocoa_RaiseWindow(_THIS, SDL_Window * window)
  10.440  {
  10.441 -    @autoreleasepool {
  10.442 -        NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
  10.443 -        [nswindow makeKeyAndOrderFront:nil];
  10.444 -    }
  10.445 +    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
  10.446 +    NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
  10.447 +
  10.448 +    [nswindow makeKeyAndOrderFront:nil];
  10.449 +    [pool release];
  10.450  }
  10.451  
  10.452  void
  10.453  Cocoa_MaximizeWindow(_THIS, SDL_Window * window)
  10.454  {
  10.455 -    @autoreleasepool {
  10.456 -        NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
  10.457 -        [nswindow zoom:nil];
  10.458 +    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
  10.459 +    NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
  10.460 +
  10.461 +    [nswindow zoom:nil];
  10.462  
  10.463 -        if (window == _this->current_glwin) {
  10.464 -            [((NSOpenGLContext *) _this->current_glctx) update];
  10.465 -        }
  10.466 +    if (window == _this->current_glwin) {
  10.467 +        [((NSOpenGLContext *) _this->current_glctx) update];
  10.468      }
  10.469 +
  10.470 +    [pool release];
  10.471  }
  10.472  
  10.473  void
  10.474  Cocoa_MinimizeWindow(_THIS, SDL_Window * window)
  10.475  {
  10.476 -    @autoreleasepool {
  10.477 -        NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
  10.478 -        [nswindow miniaturize:nil];
  10.479 -    }
  10.480 +    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
  10.481 +    NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
  10.482 +
  10.483 +    [nswindow miniaturize:nil];
  10.484 +    [pool release];
  10.485  }
  10.486  
  10.487  void
  10.488  Cocoa_RestoreWindow(_THIS, SDL_Window * window)
  10.489  {
  10.490 -    @autoreleasepool {
  10.491 -        NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
  10.492 +    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
  10.493 +    NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
  10.494  
  10.495 -        if ([nswindow isMiniaturized]) {
  10.496 -            [nswindow deminiaturize:nil];
  10.497 -        } else if ((window->flags & SDL_WINDOW_RESIZABLE) && [nswindow isZoomed]) {
  10.498 -            [nswindow zoom:nil];
  10.499 -        }
  10.500 +    if ([nswindow isMiniaturized]) {
  10.501 +        [nswindow deminiaturize:nil];
  10.502 +    } else if ((window->flags & SDL_WINDOW_RESIZABLE) && [nswindow isZoomed]) {
  10.503 +        [nswindow zoom:nil];
  10.504      }
  10.505 +    [pool release];
  10.506  }
  10.507  
  10.508  static NSWindow *
  10.509 @@ -837,95 +854,96 @@
  10.510  {
  10.511      /* this message arrived in 10.6. You're out of luck on older OSes. */
  10.512  #if MAC_OS_X_VERSION_MAX_ALLOWED >= 1060
  10.513 -    @autoreleasepool {
  10.514 -        NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
  10.515 -        if ([nswindow respondsToSelector:@selector(setStyleMask:)]) {
  10.516 -            [nswindow setStyleMask:GetWindowStyle(window)];
  10.517 -            if (bordered) {
  10.518 -                Cocoa_SetWindowTitle(_this, window);  // this got blanked out.
  10.519 -            }
  10.520 +    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
  10.521 +    NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
  10.522 +    if ([nswindow respondsToSelector:@selector(setStyleMask:)]) {
  10.523 +        [nswindow setStyleMask:GetWindowStyle(window)];
  10.524 +        if (bordered) {
  10.525 +            Cocoa_SetWindowTitle(_this, window);  // this got blanked out.
  10.526          }
  10.527      }
  10.528 +    [pool release];
  10.529  #endif
  10.530  }
  10.531  
  10.532  void
  10.533  Cocoa_SetWindowFullscreen(_THIS, SDL_Window * window, SDL_VideoDisplay * display, SDL_bool fullscreen)
  10.534  {
  10.535 -    @autoreleasepool {
  10.536 -        SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
  10.537 -        NSWindow *nswindow = data->nswindow;
  10.538 -        NSRect rect;
  10.539 +    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
  10.540 +    SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
  10.541 +    NSWindow *nswindow = data->nswindow;
  10.542 +    NSRect rect;
  10.543 +
  10.544 +    /* The view responder chain gets messed with during setStyleMask */
  10.545 +    if ([[nswindow contentView] nextResponder] == data->listener) {
  10.546 +        [[nswindow contentView] setNextResponder:nil];
  10.547 +    }
  10.548  
  10.549 -        /* The view responder chain gets messed with during setStyleMask */
  10.550 -        if ([[nswindow contentView] nextResponder] == data->listener) {
  10.551 -            [[nswindow contentView] setNextResponder:nil];
  10.552 +    if (fullscreen) {
  10.553 +        SDL_Rect bounds;
  10.554 +
  10.555 +        Cocoa_GetDisplayBounds(_this, display, &bounds);
  10.556 +        rect.origin.x = bounds.x;
  10.557 +        rect.origin.y = bounds.y;
  10.558 +        rect.size.width = bounds.w;
  10.559 +        rect.size.height = bounds.h;
  10.560 +        ConvertNSRect(&rect);
  10.561 +
  10.562 +        /* Hack to fix origin on Mac OS X 10.4 */
  10.563 +        NSRect screenRect = [[nswindow screen] frame];
  10.564 +        if (screenRect.size.height >= 1.0f) {
  10.565 +            rect.origin.y += (screenRect.size.height - rect.size.height);
  10.566          }
  10.567  
  10.568 -        if (fullscreen) {
  10.569 -            SDL_Rect bounds;
  10.570 -
  10.571 -            Cocoa_GetDisplayBounds(_this, display, &bounds);
  10.572 -            rect.origin.x = bounds.x;
  10.573 -            rect.origin.y = bounds.y;
  10.574 -            rect.size.width = bounds.w;
  10.575 -            rect.size.height = bounds.h;
  10.576 -            ConvertNSRect(&rect);
  10.577 -
  10.578 -            /* Hack to fix origin on Mac OS X 10.4 */
  10.579 -            NSRect screenRect = [[nswindow screen] frame];
  10.580 -            if (screenRect.size.height >= 1.0f) {
  10.581 -                rect.origin.y += (screenRect.size.height - rect.size.height);
  10.582 -            }
  10.583 -
  10.584 -            if ([nswindow respondsToSelector: @selector(setStyleMask:)]) {
  10.585 -                [nswindow performSelector: @selector(setStyleMask:) withObject: (id)NSBorderlessWindowMask];
  10.586 -            } else {
  10.587 -                nswindow = Cocoa_RebuildWindow(data, nswindow, NSBorderlessWindowMask);
  10.588 -            }
  10.589 +        if ([nswindow respondsToSelector: @selector(setStyleMask:)]) {
  10.590 +            [nswindow performSelector: @selector(setStyleMask:) withObject: (id)NSBorderlessWindowMask];
  10.591          } else {
  10.592 -            rect.origin.x = window->windowed.x;
  10.593 -            rect.origin.y = window->windowed.y;
  10.594 -            rect.size.width = window->windowed.w;
  10.595 -            rect.size.height = window->windowed.h;
  10.596 -            ConvertNSRect(&rect);
  10.597 +            nswindow = Cocoa_RebuildWindow(data, nswindow, NSBorderlessWindowMask);
  10.598 +        }
  10.599 +    } else {
  10.600 +        rect.origin.x = window->windowed.x;
  10.601 +        rect.origin.y = window->windowed.y;
  10.602 +        rect.size.width = window->windowed.w;
  10.603 +        rect.size.height = window->windowed.h;
  10.604 +        ConvertNSRect(&rect);
  10.605  
  10.606 -            if ([nswindow respondsToSelector: @selector(setStyleMask:)]) {
  10.607 -                [nswindow performSelector: @selector(setStyleMask:) withObject: (id)(uintptr_t)GetWindowStyle(window)];
  10.608 -            } else {
  10.609 -                nswindow = Cocoa_RebuildWindow(data, nswindow, GetWindowStyle(window));
  10.610 -            }
  10.611 -        }
  10.612 -
  10.613 -        /* The view responder chain gets messed with during setStyleMask */
  10.614 -        if ([[nswindow contentView] nextResponder] != data->listener) {
  10.615 -            [[nswindow contentView] setNextResponder:data->listener];
  10.616 -        }
  10.617 -
  10.618 -        s_moveHack = 0;
  10.619 -        [nswindow setFrameOrigin:rect.origin];
  10.620 -        [nswindow setContentSize:rect.size];
  10.621 -        s_moveHack = SDL_GetTicks();
  10.622 -
  10.623 -        /* When the window style changes the title is cleared */
  10.624 -        if (!fullscreen) {
  10.625 -            Cocoa_SetWindowTitle(_this, window);
  10.626 -        }
  10.627 -
  10.628 -    #ifdef FULLSCREEN_TOGGLEABLE
  10.629 -        if (SDL_ShouldAllowTopmost() && fullscreen) {
  10.630 -            /* OpenGL is rendering to the window, so make it visible! */
  10.631 -            [nswindow setLevel:CGShieldingWindowLevel()];
  10.632 +        if ([nswindow respondsToSelector: @selector(setStyleMask:)]) {
  10.633 +            [nswindow performSelector: @selector(setStyleMask:) withObject: (id)(uintptr_t)GetWindowStyle(window)];
  10.634          } else {
  10.635 -            [nswindow setLevel:kCGNormalWindowLevel];
  10.636 -        }
  10.637 -    #endif
  10.638 -        [nswindow makeKeyAndOrderFront:nil];
  10.639 -
  10.640 -        if (window == _this->current_glwin) {
  10.641 -            [((NSOpenGLContext *) _this->current_glctx) update];
  10.642 +            nswindow = Cocoa_RebuildWindow(data, nswindow, GetWindowStyle(window));
  10.643          }
  10.644      }
  10.645 +
  10.646 +    /* The view responder chain gets messed with during setStyleMask */
  10.647 +    if ([[nswindow contentView] nextResponder] != data->listener) {
  10.648 +        [[nswindow contentView] setNextResponder:data->listener];
  10.649 +    }
  10.650 +
  10.651 +    s_moveHack = 0;
  10.652 +    [nswindow setFrameOrigin:rect.origin];
  10.653 +    [nswindow setContentSize:rect.size];
  10.654 +    s_moveHack = SDL_GetTicks();
  10.655 +
  10.656 +    /* When the window style changes the title is cleared */
  10.657 +    if (!fullscreen) {
  10.658 +        Cocoa_SetWindowTitle(_this, window);
  10.659 +    }
  10.660 +
  10.661 +#ifdef FULLSCREEN_TOGGLEABLE
  10.662 +    if (SDL_ShouldAllowTopmost() && fullscreen) {
  10.663 +        /* OpenGL is rendering to the window, so make it visible! */
  10.664 +        [nswindow setLevel:CGShieldingWindowLevel()];
  10.665 +    } else {
  10.666 +        [nswindow setLevel:kCGNormalWindowLevel];
  10.667 +    }
  10.668 +#endif
  10.669 +    [nswindow makeKeyAndOrderFront:nil];
  10.670 +
  10.671 +    if (window == _this->current_glwin) {
  10.672 +        [((NSOpenGLContext *) _this->current_glctx) update];
  10.673 +    }
  10.674 +
  10.675 +    [pool release];
  10.676  }
  10.677  
  10.678  int
  10.679 @@ -1009,18 +1027,18 @@
  10.680  void
  10.681  Cocoa_DestroyWindow(_THIS, SDL_Window * window)
  10.682  {
  10.683 -    @autoreleasepool {
  10.684 -        SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
  10.685 +    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
  10.686 +    SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
  10.687  
  10.688 -        if (data) {
  10.689 -            [data->listener close];
  10.690 -            [data->listener release];
  10.691 -            if (data->created) {
  10.692 -                [data->nswindow close];
  10.693 -            }
  10.694 -            SDL_free(data);
  10.695 +    if (data) {
  10.696 +        [data->listener close];
  10.697 +        [data->listener release];
  10.698 +        if (data->created) {
  10.699 +            [data->nswindow close];
  10.700          }
  10.701 +        SDL_free(data);
  10.702      }
  10.703 +    [pool release];
  10.704  }
  10.705  
  10.706  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  
   11.19 -        NSString* ns_string_file_component = [file_manager stringWithFileSystemRepresentation:file length:strlen(file)];
   11.20 +	NSFileManager* file_manager = [NSFileManager defaultManager];
   11.21 +	NSString* resource_path = [[NSBundle mainBundle] resourcePath];
   11.22 +
   11.23 +	NSString* ns_string_file_component = [file_manager stringWithFileSystemRepresentation:file length:strlen(file)];
   11.24  
   11.25 -        NSString* full_path_with_file_to_try = [resource_path stringByAppendingPathComponent:ns_string_file_component];
   11.26 -        if ([file_manager fileExistsAtPath:full_path_with_file_to_try]) {
   11.27 -            fp = fopen([full_path_with_file_to_try fileSystemRepresentation], mode);
   11.28 -        } else {
   11.29 -            fp = fopen(file, mode);
   11.30 -        }
   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