changeset 287:fdb1e98fd8b6

* Create an autorelease pool, so autoreleased SDL objects don't leak (Mac OS X specific issue) * Patch by nschum
author mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
date Sun, 21 Jun 2009 15:43:12 +0000
parents bbabe4942150
children e194eb289fb0
files build/darwin-config-dist.py engine/core/controller/engine.cpp engine/core/controller/engine.h
diffstat 3 files changed, 21 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/build/darwin-config-dist.py	Sun Jun 21 15:09:54 2009 +0000
+++ b/build/darwin-config-dist.py	Sun Jun 21 15:43:12 2009 +0000
@@ -46,6 +46,7 @@
 
 	context.CheckHeader('SDL/SDL_image.h')
 	context.CheckHeader('SDL/SDL_ttf.h')
+	context.checkSimpleLib(['objc'])
 	context.checkSimpleLib(['vorbisfile'], 'vorbisfile.h')
 	context.checkSimpleLib(['guichan'])
 	context.checkSimpleLib(['guichan_sdl'])
--- a/engine/core/controller/engine.cpp	Sun Jun 21 15:09:54 2009 +0000
+++ b/engine/core/controller/engine.cpp	Sun Jun 21 15:43:12 2009 +0000
@@ -77,6 +77,8 @@
 #include "engine.h"
 
 #ifdef USE_COCOA
+
+#include <objc/message.h>
 #include <dlfcn.h>
 
 int main(int argc, char **argv)
@@ -112,6 +114,11 @@
 		void (*nsappload)(void);
 		nsappload = (void(*)()) dlsym( cocoa_lib, "NSApplicationLoad");
 		nsappload();
+
+		// Create an autorelease pool, so autoreleased SDL objects don't leak.
+		objc_object *NSAutoreleasePool = objc_getClass("NSAutoreleasePool");
+		m_autoreleasePool =
+			objc_msgSend(NSAutoreleasePool, sel_registerName("new"));
 #endif
 		preInit();
 	}
@@ -281,6 +288,9 @@
 
 		TTF_Quit();
 		SDL_Quit();
+#ifdef USE_COCOA
+		objc_msgSend(m_autoreleasePool, sel_registerName("release"));
+#endif
 		FL_LOG(_log, "================== Engine destructed ==================");
 		m_destroyed = true;
 		//delete m_logmanager;
--- a/engine/core/controller/engine.h	Sun Jun 21 15:09:54 2009 +0000
+++ b/engine/core/controller/engine.h	Sun Jun 21 15:43:12 2009 +0000
@@ -27,6 +27,11 @@
 #include <string>
 #include <vector>
 
+// Platform specific includes
+#ifdef USE_COCOA
+#include <objc/runtime.h>
+#endif
+
 // 3rd party library includes
 #include <SDL.h>
 
@@ -179,6 +184,11 @@
 		bool m_destroyed;
 		
 		EngineSettings m_settings;
+
+#ifdef USE_COCOA
+		objc_object *m_autoreleasePool;
+#endif
+
 	};
 
 }//FIFE