Fixed several crash/mem leak issue related to multiple device init/shutdown.

This commit is contained in:
Branimir Karadžić 2017-09-01 14:18:19 -07:00
parent 50d0488b1f
commit 7d7c53967a
1 changed files with 17 additions and 4 deletions

View File

@ -432,6 +432,7 @@ namespace bgfx { namespace mtl
return false;
}
retain(m_device);
m_metalLayer.device = m_device;
m_metalLayer.pixelFormat = MTLPixelFormatBGRA8Unorm;
@ -488,6 +489,7 @@ namespace bgfx { namespace mtl
}
m_screenshotBlitProgram.create(&m_screenshotBlitProgramVsh, &m_screenshotBlitProgramFsh);
release(lib);
reset(m_renderPipelineDescriptor);
m_renderPipelineDescriptor.colorAttachments[0].pixelFormat = m_metalLayer.pixelFormat;
@ -672,6 +674,11 @@ namespace bgfx { namespace mtl
m_textures[ii].destroy();
}
m_screenshotBlitProgramVsh.destroy();
m_screenshotBlitProgramFsh.destroy();
m_screenshotBlitProgram.destroy();
MTL_RELEASE(m_screenshotBlitRenderPipelineState);
captureFinish();
MTL_RELEASE(m_depthStencilDescriptor);
@ -683,10 +690,7 @@ namespace bgfx { namespace mtl
MTL_RELEASE(m_samplerDescriptor);
MTL_RELEASE(m_backBufferDepth);
if (BX_ENABLED(BX_PLATFORM_IOS) )
{
MTL_RELEASE(m_backBufferStencil);
}
MTL_RELEASE(m_backBufferStencil);
for (uint8_t i=0; i < MTL_MAX_FRAMES_IN_FLIGHT; ++i)
{
@ -1170,11 +1174,18 @@ namespace bgfx { namespace mtl
{
release(m_backBufferDepth);
}
m_backBufferDepth = m_device.newTextureWithDescriptor(m_textureDescriptor);
if (NULL != m_backBufferStencil)
{
release(m_backBufferStencil);
}
if (m_hasPixelFormatDepth32Float_Stencil8)
{
m_backBufferStencil = m_backBufferDepth;
retain(m_backBufferStencil);
}
else
{
@ -1915,6 +1926,7 @@ namespace bgfx { namespace mtl
if (NULL != lib)
{
m_function = lib.newFunctionWithName(SHADER_FUNCTION_NAME);
release(lib);
}
BGFX_FATAL(NULL != m_function
@ -2831,6 +2843,7 @@ namespace bgfx { namespace mtl
void CommandQueueMtl::shutdown()
{
finish(true);
MTL_RELEASE(m_commandQueue);
}