From 397265f2fc786f7d25ea32984abda9ddd6228390 Mon Sep 17 00:00:00 2001 From: Vas Crabb Date: Fri, 3 Apr 2015 01:53:48 +1100 Subject: [PATCH] bgfx: fix leak of autoreleased objects and support OS X 10.6 Snow Leopard --- 3rdparty/bgfx/src/glcontext_nsgl.mm | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/3rdparty/bgfx/src/glcontext_nsgl.mm b/3rdparty/bgfx/src/glcontext_nsgl.mm index 667fdf4f0b3..f01c7014131 100644 --- a/3rdparty/bgfx/src/glcontext_nsgl.mm +++ b/3rdparty/bgfx/src/glcontext_nsgl.mm @@ -7,6 +7,7 @@ #if BX_PLATFORM_OSX && (BGFX_CONFIG_RENDERER_OPENGLES || BGFX_CONFIG_RENDERER_OPENGL) # include "renderer_gl.h" +# include # include # include @@ -36,6 +37,22 @@ namespace bgfx { namespace gl } }; + class AutoreleasePoolHolder + { + public: + AutoreleasePoolHolder() : pool([[NSAutoreleasePool alloc] init]) + { + } + + ~AutoreleasePoolHolder() + { + [pool release]; + } + + private: + NSAutoreleasePool* pool; + }; + static void* s_opengl = NULL; void GlContext::create(uint32_t _width, uint32_t _height) @@ -45,11 +62,13 @@ namespace bgfx { namespace gl s_opengl = bx::dlopen("/System/Library/Frameworks/OpenGL.framework/Versions/Current/OpenGL"); BX_CHECK(NULL != s_opengl, "OpenGL dynamic library is not found!"); + const AutoreleasePoolHolder pool; NSWindow* nsWindow = (NSWindow*)g_bgfxNSWindow; m_context = g_bgfxNSGL; if (NULL == g_bgfxNSGL) { +#if defined(MAC_OS_X_VERSION_MAX_ALLOWED) && (MAC_OS_X_VERSION_MAX_ALLOWED >= 1070) NSOpenGLPixelFormatAttribute profile = #if BGFX_CONFIG_RENDERER_OPENGL >= 31 NSOpenGLProfileVersion3_2Core @@ -57,9 +76,12 @@ namespace bgfx { namespace gl NSOpenGLProfileVersionLegacy #endif // BGFX_CONFIG_RENDERER_OPENGL >= 31 ; +#endif // defined(MAC_OS_X_VERSION_MAX_ALLOWED) && (MAC_OS_X_VERSION_MAX_ALLOWED >= 1070) NSOpenGLPixelFormatAttribute pixelFormatAttributes[] = { +#if defined(MAC_OS_X_VERSION_MAX_ALLOWED) && (MAC_OS_X_VERSION_MAX_ALLOWED >= 1070) NSOpenGLPFAOpenGLProfile, profile, +#endif // defined(MAC_OS_X_VERSION_MAX_ALLOWED) && (MAC_OS_X_VERSION_MAX_ALLOWED >= 1070) NSOpenGLPFAColorSize, 24, NSOpenGLPFAAlphaSize, 8, NSOpenGLPFADepthSize, 24,