From 5cdd4de559a114dd30c20537bccddf6a442579e4 Mon Sep 17 00:00:00 2001 From: Attila Kocsis Date: Thu, 10 Jan 2019 20:25:06 +0100 Subject: [PATCH] Moved autoreleasepool into renderframe --- examples/common/entry/entry_osx.mm | 5 ++++- src/bgfx.cpp | 26 +++++++++++++++++++++++++- src/renderer_mtl.mm | 16 ---------------- 3 files changed, 29 insertions(+), 18 deletions(-) diff --git a/examples/common/entry/entry_osx.mm b/examples/common/entry/entry_osx.mm index 5ece40af6..623d3be80 100644 --- a/examples/common/entry/entry_osx.mm +++ b/examples/common/entry/entry_osx.mm @@ -461,8 +461,11 @@ namespace entry { bgfx::renderFrame(); - while (dispatchEvent(peekEvent() ) ) + @autoreleasepool { + while (dispatchEvent(peekEvent() ) ) + { + } } } diff --git a/src/bgfx.cpp b/src/bgfx.cpp index 4918a80ad..cea1d174c 100644 --- a/src/bgfx.cpp +++ b/src/bgfx.cpp @@ -12,6 +12,10 @@ #include "topology.h" +#if BX_PLATFORM_OSX +#include +#endif + BX_ERROR_RESULT(BGFX_ERROR_TEXTURE_VALIDATION, BX_MAKEFOURCC('b', 'g', 0, 1) ); namespace bgfx @@ -2182,11 +2186,31 @@ namespace bgfx } } } - + +#if BX_PLATFORM_OSX + struct NSAutoreleasePoolScope + { + NSAutoreleasePoolScope() + { + id obj = class_createInstance(objc_getClass("NSAutoreleasePool"),0); + pool = objc_msgSend(obj, sel_getUid("init")); + } + ~NSAutoreleasePoolScope() + { + objc_msgSend(pool, sel_getUid("release")); + } + id pool; + }; +#endif + RenderFrame::Enum Context::renderFrame(int32_t _msecs) { BGFX_PROFILER_SCOPE("bgfx::renderFrame", 0xff2040ff); +#if BX_PLATFORM_OSX + NSAutoreleasePoolScope pool; +#endif + if (!m_flipAfterRender) { BGFX_PROFILER_SCOPE("bgfx/flip", 0xff2040ff); diff --git a/src/renderer_mtl.mm b/src/renderer_mtl.mm index 395025dc6..30fc89034 100644 --- a/src/renderer_mtl.mm +++ b/src/renderer_mtl.mm @@ -639,18 +639,11 @@ namespace bgfx { namespace mtl g_internalData.context = m_device; -#if BX_PLATFORM_OSX - m_pool = [[NSAutoreleasePool alloc] init]; -#endif return true; } void shutdown() { -#if BX_PLATFORM_OSX - [m_pool release]; -#endif - m_occlusionQuery.postReset(); m_gpuTimer.shutdown(); @@ -1186,11 +1179,6 @@ namespace bgfx { namespace mtl m_cmd.kick(true); m_commandBuffer = 0; - -#if BX_PLATFORM_OSX - [m_pool release]; - m_pool = [[NSAutoreleasePool alloc] init]; -#endif } void updateResolution(const Resolution& _resolution) @@ -2308,10 +2296,6 @@ namespace bgfx { namespace mtl RenderCommandEncoder m_renderCommandEncoder; ComputeCommandEncoder m_computeCommandEncoder; FrameBufferHandle m_renderCommandEncoderFrameBufferHandle; - -#if BX_PLATFORM_OSX - NSAutoreleasePool* m_pool; -#endif }; RendererContextI* rendererCreate(const Init& _init)