Răsfoiți Sursa

Moved autoreleasepool into renderframe

Attila Kocsis 7 ani în urmă
părinte
comite
5cdd4de559
3 a modificat fișierele cu 29 adăugiri și 18 ștergeri
  1. 4 1
      examples/common/entry/entry_osx.mm
  2. 25 1
      src/bgfx.cpp
  3. 0 16
      src/renderer_mtl.mm

+ 4 - 1
examples/common/entry/entry_osx.mm

@@ -461,8 +461,11 @@ namespace entry
 			{
 				bgfx::renderFrame();
 
-				while (dispatchEvent(peekEvent() ) )
+				@autoreleasepool
 				{
+					while (dispatchEvent(peekEvent() ) )
+					{
+					}
 				}
 			}
 

+ 25 - 1
src/bgfx.cpp

@@ -12,6 +12,10 @@
 
 #include "topology.h"
 
+#if BX_PLATFORM_OSX
+#include <objc/message.h>
+#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);

+ 0 - 16
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)