From 324d4a18e716070582fc8e659387f9b72a3d42a3 Mon Sep 17 00:00:00 2001 From: Marco Antognini Date: Sun, 13 Apr 2014 13:06:42 +0200 Subject: [PATCH] Fixed NSApplication not retaining its delegate --- src/SFML/Window/OSX/SFApplicationDelegate.h | 6 ++++++ src/SFML/Window/OSX/SFApplicationDelegate.m | 8 ++++++++ src/SFML/Window/OSX/WindowImplCocoa.mm | 2 +- 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/SFML/Window/OSX/SFApplicationDelegate.h b/src/SFML/Window/OSX/SFApplicationDelegate.h index ed0fd178..05f89cfe 100644 --- a/src/SFML/Window/OSX/SFApplicationDelegate.h +++ b/src/SFML/Window/OSX/SFApplicationDelegate.h @@ -50,4 +50,10 @@ //////////////////////////////////////////////////////////// -(BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication*)theApplication; +//////////////////////////////////////////////////////////// +/// \brief Return a singleton instance of this class +/// +//////////////////////////////////////////////////////////// ++(id)instance; + @end diff --git a/src/SFML/Window/OSX/SFApplicationDelegate.m b/src/SFML/Window/OSX/SFApplicationDelegate.m index c22b720b..b1567897 100644 --- a/src/SFML/Window/OSX/SFApplicationDelegate.m +++ b/src/SFML/Window/OSX/SFApplicationDelegate.m @@ -49,6 +49,14 @@ return YES; } +//////////////////////////////////////////////////////////// ++(id)instance +{ + static SFApplicationDelegate* singleton = nil; + if (singleton == nil) + singleton = [[SFApplicationDelegate alloc] init]; + return singleton; +} @end diff --git a/src/SFML/Window/OSX/WindowImplCocoa.mm b/src/SFML/Window/OSX/WindowImplCocoa.mm index 7d519462..909146a2 100644 --- a/src/SFML/Window/OSX/WindowImplCocoa.mm +++ b/src/SFML/Window/OSX/WindowImplCocoa.mm @@ -139,7 +139,7 @@ void WindowImplCocoa::setUpProcess(void) // Register an application delegate if there is none if (![[SFApplication sharedApplication] delegate]) - [NSApp setDelegate:[[SFApplicationDelegate alloc] init]]; + [NSApp setDelegate:[SFApplicationDelegate instance]]; // Create menus for the application (before finishing launching!) [SFApplication setUpMenuBar];