From 1634742177eded4b8412d7ab11494ed662d20905 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Sun, 4 Jan 2015 17:49:12 +0100 Subject: [PATCH] Fixed lifetime management of application delegate. --- src/cocoa_init.m | 6 +++--- src/cocoa_platform.h | 1 + src/cocoa_window.m | 6 +++--- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/cocoa_init.m b/src/cocoa_init.m index 1bcee9d9..8779cdfa 100644 --- a/src/cocoa_init.m +++ b/src/cocoa_init.m @@ -228,11 +228,11 @@ void _glfwPlatformTerminate(void) _glfw.ns.eventSource = NULL; } - id delegate = [NSApp delegate]; - if (delegate) + if (_glfw.ns.delegate) { - [delegate release]; [NSApp setDelegate:nil]; + [_glfw.ns.delegate release]; + _glfw.ns.delegate = nil; } [_glfw.ns.autoreleasePool release]; diff --git a/src/cocoa_platform.h b/src/cocoa_platform.h index a68ced09..7e131be6 100644 --- a/src/cocoa_platform.h +++ b/src/cocoa_platform.h @@ -76,6 +76,7 @@ typedef struct _GLFWwindowNS typedef struct _GLFWlibraryNS { CGEventSourceRef eventSource; + id delegate; id autoreleasePool; id cursor; diff --git a/src/cocoa_window.m b/src/cocoa_window.m index d92915bc..30adf75e 100644 --- a/src/cocoa_window.m +++ b/src/cocoa_window.m @@ -794,15 +794,15 @@ static GLboolean initializeAppKit(void) // There can only be one application delegate, but we allocate it the // first time a window is created to keep all window code in this file - id delegate = [[GLFWApplicationDelegate alloc] init]; - if (delegate == nil) + _glfw.ns.delegate = [[GLFWApplicationDelegate alloc] init]; + if (_glfw.ns.delegate == nil) { _glfwInputError(GLFW_PLATFORM_ERROR, "Cocoa: Failed to create application delegate"); return GL_FALSE; } - [NSApp setDelegate:delegate]; + [NSApp setDelegate:_glfw.ns.delegate]; [NSApp run]; return GL_TRUE;