Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

Fixed Objective-C memory leaks

Send an SDL quit event when Command-Q is pressed.
  • Loading branch information
slouken committed Jul 25, 2006
1 parent dafecf2 commit e8fb8b6068605cdee897178742c63797b4603164
Showing with 31 additions and 3 deletions.
  1. +15 −0 src/video/cocoa/SDL_cocoaevents.m
  2. +16 −3 src/video/cocoa/SDL_cocoawindow.m
@@ -37,6 +37,18 @@ - (void)setRunning
}
@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 @@ - (void)setRunning
}
[NSApp finishLaunching];
}
if ([NSApp delegate] == nil) {
[NSApp setDelegate:[[SDLAppDelegate alloc] init]];
}
[NSApp setRunning];
[pool release];
}
@@ -419,18 +419,21 @@ - (void)keyUp:(NSEvent *)theEvent
void
Cocoa_SetWindowTitle(_THIS, SDL_Window * window)
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->window;
NSString *string;

string = [[NSString alloc] initWithUTF8String:window->title];
[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 @@ - (void)keyUp:(NSEvent *)theEvent
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)keyUp:(NSEvent *)theEvent
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)keyUp:(NSEvent *)theEvent
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

0 comments on commit e8fb8b6

Please sign in to comment.