Mercurial > sdl-ios-xcode
changeset 1937:05e88d266921
Fixed Objective-C memory leaks
Send an SDL quit event when Command-Q is pressed.
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Tue, 25 Jul 2006 06:59:14 +0000 |
parents | 83946ee0ff1f |
children | 861893943d53 |
files | src/video/cocoa/SDL_cocoaevents.m src/video/cocoa/SDL_cocoawindow.m |
diffstat | 2 files changed, 31 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/src/video/cocoa/SDL_cocoaevents.m Tue Jul 25 06:22:42 2006 +0000 +++ b/src/video/cocoa/SDL_cocoaevents.m Tue Jul 25 06:59:14 2006 +0000 @@ -37,6 +37,18 @@ } @end +@interface SDLAppDelegate : NSObject +- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender; +@end + +@implementation SDLAppDelegate : NSObject +- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender +{ + SDL_SendQuit(); + return NSTerminateCancel; +} +@end + static NSString * GetApplicationName(void) { @@ -139,6 +151,9 @@ } [NSApp finishLaunching]; } + if ([NSApp delegate] == nil) { + [NSApp setDelegate:[[SDLAppDelegate alloc] init]]; + } [NSApp setRunning]; [pool release]; }
--- a/src/video/cocoa/SDL_cocoawindow.m Tue Jul 25 06:22:42 2006 +0000 +++ b/src/video/cocoa/SDL_cocoawindow.m Tue Jul 25 06:59:14 2006 +0000 @@ -419,6 +419,7 @@ void Cocoa_SetWindowTitle(_THIS, SDL_Window * window) { + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->window; NSString *string; @@ -426,11 +427,13 @@ [nswindow setTitle:string]; [nswindow setMiniwindowTitle:string]; [string release]; + [pool release]; } void Cocoa_SetWindowPosition(_THIS, SDL_Window * window) { + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->window; NSRect rect; @@ -441,25 +444,30 @@ ConvertNSRect(&rect); rect = [nswindow frameRectForContentRect:rect]; [nswindow setFrameOrigin:rect.origin]; + [pool release]; } void Cocoa_SetWindowSize(_THIS, SDL_Window * window) { + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->window; NSSize size; size.width = window->w; size.height = window->h; [nswindow setContentSize:size]; + [pool release]; } void Cocoa_ShowWindow(_THIS, SDL_Window * window) { + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->window; [nswindow makeKeyAndOrderFront:nil]; + [pool release]; } void @@ -473,25 +481,31 @@ void Cocoa_RaiseWindow(_THIS, SDL_Window * window) { + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->window; [nswindow makeKeyAndOrderFront:nil]; + [pool release]; } void Cocoa_MaximizeWindow(_THIS, SDL_Window * window) { + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->window; [nswindow performZoom:nil]; + [pool release]; } void Cocoa_MinimizeWindow(_THIS, SDL_Window * window) { + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->window; [nswindow performMiniaturize:nil]; + [pool release]; } void @@ -516,24 +530,23 @@ void Cocoa_DestroyWindow(_THIS, SDL_Window * window) { + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; SDL_WindowData *data = (SDL_WindowData *) window->driverdata; if (data) { - NSAutoreleasePool *pool; #ifdef SDL_VIDEO_OPENGL if (window->flags & SDL_WINDOW_OPENGL) { Cocoa_GL_CleanupWindow(_this, window); } #endif - pool = [[NSAutoreleasePool alloc] init]; [data->listener close]; [data->listener release]; if (data->created) { [data->window close]; } SDL_free(data); - [pool release]; } + [pool release]; } SDL_bool