From b285639d9b96fe48a1fa83f4f6cc23ea5b987fd1 Mon Sep 17 00:00:00 2001 From: azhirnov Date: Thu, 11 Feb 2021 23:43:34 +0300 Subject: fixed mem leak in root signature cache in dx12 --- .../GraphicsEngineD3D12/src/RenderDeviceD3D12Impl.cpp | 1 + Graphics/GraphicsEngineD3D12/src/RootSignature.cpp | 16 +++++++--------- 2 files changed, 8 insertions(+), 9 deletions(-) (limited to 'Graphics/GraphicsEngineD3D12') diff --git a/Graphics/GraphicsEngineD3D12/src/RenderDeviceD3D12Impl.cpp b/Graphics/GraphicsEngineD3D12/src/RenderDeviceD3D12Impl.cpp index b8667f78..fb0f5c43 100644 --- a/Graphics/GraphicsEngineD3D12/src/RenderDeviceD3D12Impl.cpp +++ b/Graphics/GraphicsEngineD3D12/src/RenderDeviceD3D12Impl.cpp @@ -855,6 +855,7 @@ DescriptorHeapAllocation RenderDeviceD3D12Impl::AllocateGPUDescriptors(D3D12_DES void RenderDeviceD3D12Impl::CreateRootSignature(const RefCntAutoPtr* ppSignatures, Uint32 SignatureCount, RootSignatureD3D12** ppRootSig) { RootSignatureD3D12* pRootSigD3D12(NEW_RC_OBJ(m_RootSignatureAllocator, "RootSignatureD3D12 instance", RootSignatureD3D12)(this, ppSignatures, SignatureCount)); + pRootSigD3D12->AddRef(); *ppRootSig = pRootSigD3D12; } diff --git a/Graphics/GraphicsEngineD3D12/src/RootSignature.cpp b/Graphics/GraphicsEngineD3D12/src/RootSignature.cpp index acc5042c..e10ee9b3 100644 --- a/Graphics/GraphicsEngineD3D12/src/RootSignature.cpp +++ b/Graphics/GraphicsEngineD3D12/src/RootSignature.cpp @@ -287,7 +287,7 @@ RootSignatureCacheD3D12::~RootSignatureCacheD3D12() RefCntAutoPtr RootSignatureCacheD3D12::GetRootSig(const RefCntAutoPtr* ppSignatures, Uint32 SignatureCount) { - RootSignatureD3D12* pNewRootSig = nullptr; + RefCntAutoPtr pNewRootSig; m_DeviceD3D12Impl.CreateRootSignature(ppSignatures, SignatureCount, &pNewRootSig); if (pNewRootSig == nullptr) @@ -298,19 +298,17 @@ RefCntAutoPtr RootSignatureCacheD3D12::GetRootSig(const RefC { std::lock_guard Lock{m_RootSigCacheGuard}; - auto IterAndFlag = m_RootSigCache.insert(pNewRootSig); + auto IterAndFlag = m_RootSigCache.insert(pNewRootSig.RawPtr()); Inserted = IterAndFlag.second; if (Inserted) + { pNewRootSig->Finalize(); - - Result = *IterAndFlag.first; + Result = std::move(pNewRootSig); + } + else + Result = *IterAndFlag.first; } - - // Destroy outside of mutex scope. - if (!Inserted) - pNewRootSig->~RootSignatureD3D12(); - return Result; } -- cgit v1.2.3