Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
Fixed Objective-C memory leaks
Browse files Browse the repository at this point in the history
Send an SDL quit event when Command-Q is pressed.
  • Loading branch information
slouken committed Jul 25, 2006
1 parent dafecf2 commit e8fb8b6
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
15 changes: 15 additions & 0 deletions src/video/cocoa/SDL_cocoaevents.m
Expand Up @@ -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)
{
Expand Down Expand Up @@ -139,6 +151,9 @@ - (void)setRunning
}
[NSApp finishLaunching];
}
if ([NSApp delegate] == nil) {
[NSApp setDelegate:[[SDLAppDelegate alloc] init]];
}
[NSApp setRunning];
[pool release];
}
Expand Down
19 changes: 16 additions & 3 deletions src/video/cocoa/SDL_cocoawindow.m
Expand Up @@ -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;

Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit e8fb8b6

Please sign in to comment.