diff --git a/ui/cocoa/ebiten_window.c b/ui/cocoa/ebiten_window.c index 6e4b09578..460708522 100644 --- a/ui/cocoa/ebiten_window.c +++ b/ui/cocoa/ebiten_window.c @@ -2,10 +2,10 @@ #import "ebiten_window.h" -#include - #import "ebiten_content_view.h" +@class NSOpenGLContext; + void ebiten_WindowClosed(void* nativeWindow); @implementation EbitenWindow { @@ -16,6 +16,7 @@ void ebiten_WindowClosed(void* nativeWindow); - (id)initWithSize:(NSSize)size glContext:(NSOpenGLContext*)glContext { self->glContext_ = glContext; + [self->glContext_ retain]; NSUInteger style = (NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask); @@ -35,14 +36,16 @@ void ebiten_WindowClosed(void* nativeWindow); styleMask:style backing:NSBackingStoreBuffered defer:YES]; - assert(self != nil); - [self setReleasedWhenClosed:YES]; - [self setDelegate:self]; - [self setDocumentEdited:YES]; + if (self != nil) { + [self setReleasedWhenClosed:YES]; + [self setDelegate:self]; + [self setDocumentEdited:YES]; - NSRect rect = NSMakeRect(0, 0, size.width, size.height); - NSView* contentView = [[EbitenContentView alloc] initWithFrame:rect]; - [self setContentView:contentView]; + NSRect rect = NSMakeRect(0, 0, size.width, size.height); + NSView* contentView = [[EbitenContentView alloc] initWithFrame:rect]; + [self setContentView:contentView]; + [contentView release]; + } return self; } diff --git a/ui/cocoa/mainloop.c b/ui/cocoa/mainloop.c index 771d9c4a4..8f54a39de 100644 --- a/ui/cocoa/mainloop.c +++ b/ui/cocoa/mainloop.c @@ -54,11 +54,15 @@ void* CreateWindow(size_t width, size_t height, const char* title, void* glConte EbitenWindow* window = [[EbitenWindow alloc] initWithSize:size glContext:glContext]; - [window setTitle: [[NSString alloc] - initWithUTF8String:title]]; + NSString* nsTitle = [[NSString alloc] + initWithUTF8String:title]; + [window setTitle: nsTitle]; + [nsTitle release]; + [window makeKeyAndOrderFront:nil]; - [(NSOpenGLContext*)glContext setView:[window contentView]]; + [glContext setView:[window contentView]]; + [glContext release]; return window; }