Ver Fonte

Fixed GL memory leaks.

bkaradzic há 12 anos atrás
pai
commit
45365db46a
4 ficheiros alterados com 33 adições e 10 exclusões
  1. 5 2
      src/bgfx.cpp
  2. 1 1
      src/bgfx_p.h
  3. 21 7
      src/renderer_gl.cpp
  4. 6 0
      src/renderer_gl.h

+ 5 - 2
src/bgfx.cpp

@@ -614,6 +614,8 @@ namespace bgfx
 
 
 	void init(CallbackI* _callback, bx::ReallocatorI* _allocator)
 	void init(CallbackI* _callback, bx::ReallocatorI* _allocator)
 	{
 	{
+		BX_TRACE("Init");
+
 		if (NULL != _allocator)
 		if (NULL != _allocator)
 		{
 		{
 			g_allocator = _allocator;
 			g_allocator = _allocator;
@@ -730,7 +732,6 @@ namespace bgfx
 	void Context::init(bool _createRenderThread)
 	void Context::init(bool _createRenderThread)
 	{
 	{
 		BX_CHECK(!m_rendererInitialized, "Already initialized?");
 		BX_CHECK(!m_rendererInitialized, "Already initialized?");
-		BX_TRACE("init");
 
 
 		m_exit = false;
 		m_exit = false;
 		m_frames = 0;
 		m_frames = 0;
@@ -785,11 +786,13 @@ namespace bgfx
 			bx::snprintf(name, sizeof(name), "%02d view", ii);
 			bx::snprintf(name, sizeof(name), "%02d view", ii);
 			setViewName(ii, name);
 			setViewName(ii, name);
 		}
 		}
+
+		BX_TRACE("Init complete.");
 	}
 	}
 
 
 	void Context::shutdown()
 	void Context::shutdown()
 	{
 	{
-		BX_TRACE("shutdown");
+		BX_TRACE("Shutdown");
 
 
 		getCommandBuffer(CommandBuffer::RendererShutdownBegin);
 		getCommandBuffer(CommandBuffer::RendererShutdownBegin);
 		frame();
 		frame();

+ 1 - 1
src/bgfx_p.h

@@ -306,7 +306,7 @@ namespace bgfx
 			clear();
 			clear();
 		}
 		}
 
 
-		~TextVideoMem()
+		BX_NO_INLINE ~TextVideoMem()
 		{
 		{
 			BX_FREE(g_allocator, m_mem);
 			BX_FREE(g_allocator, m_mem);
 		}
 		}

+ 21 - 7
src/renderer_gl.cpp

@@ -740,13 +740,7 @@ namespace bgfx
 			}
 			}
 			else
 			else
 			{
 			{
-				if (NULL != m_capture)
-				{
-					g_callback->captureEnd();
-					BX_FREE(g_allocator, m_capture);
-					m_capture = NULL;
-					m_captureSize = 0;
-				}
+				captureFinish();
 			}
 			}
 		}
 		}
 
 
@@ -767,6 +761,17 @@ namespace bgfx
 			}
 			}
 		}
 		}
 
 
+		void captureFinish()
+		{
+			if (NULL != m_capture)
+			{
+				g_callback->captureEnd();
+				BX_FREE(g_allocator, m_capture);
+				m_capture = NULL;
+				m_captureSize = 0;
+			}
+		}
+
 		void saveScreenShot(const char* _filePath)
 		void saveScreenShot(const char* _filePath)
 		{
 		{
 			uint32_t length = m_resolution.m_width*m_resolution.m_height*4;
 			uint32_t length = m_resolution.m_width*m_resolution.m_height*4;
@@ -825,6 +830,8 @@ namespace bgfx
 
 
 		void shutdown()
 		void shutdown()
 		{
 		{
+			captureFinish();
+
 			invalidateCache();
 			invalidateCache();
 
 
 #if BGFX_CONFIG_RENDERER_OPENGL
 #if BGFX_CONFIG_RENDERER_OPENGL
@@ -1103,6 +1110,13 @@ namespace bgfx
 
 
 	void Program::destroy()
 	void Program::destroy()
 	{
 	{
+		if (NULL != m_constantBuffer)
+		{
+			ConstantBuffer::destroy(m_constantBuffer);
+			m_constantBuffer = NULL;
+		}
+		m_numPredefined = 0;
+
 		GL_CHECK(glUseProgram(0) );
 		GL_CHECK(glUseProgram(0) );
 		GL_CHECK(glDeleteProgram(m_id) );
 		GL_CHECK(glDeleteProgram(m_id) );
 
 

+ 6 - 0
src/renderer_gl.h

@@ -656,6 +656,12 @@ namespace bgfx
 
 
 	struct Program
 	struct Program
 	{
 	{
+		Program()
+			: m_constantBuffer(NULL)
+			, m_numPredefined(0)
+		{
+		}
+
 		void create(const Shader& _vsh, const Shader& _fsh);
 		void create(const Shader& _vsh, const Shader& _fsh);
 		void destroy();
 		void destroy();
  		void init();
  		void init();