From d15177d84e9e958b8a037dd5cdd05bf206717c2d Mon Sep 17 00:00:00 2001 From: Corentin Wallez Date: Fri, 12 Jan 2018 14:18:45 -0500 Subject: [PATCH] Don't leak default created objects Sometimes NXT provides default objects for parts of the pipelines, for example a default pipeline layout. This objects were create with code like: device->CreateFooBuilder()->GetResult(); and stored in a Ref<>. This caused the object to have on external reference and two internal references and not get destroyed when the Ref<> goes out. Call Release on these objects to remove the external reference and fix the leak. Was found via the Vulkan validation layers that were complaining that a VkPipelineLayout was leaked. --- src/backend/Pipeline.cpp | 2 ++ src/backend/RenderPipeline.cpp | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/src/backend/Pipeline.cpp b/src/backend/Pipeline.cpp index 67c1c19a1f..177a2ba50f 100644 --- a/src/backend/Pipeline.cpp +++ b/src/backend/Pipeline.cpp @@ -32,6 +32,8 @@ namespace backend { ->GetDevice() ->CreatePipelineLayoutBuilder() ->GetResult(); + // Remove the external ref objects are created with + mLayout->Release(); } auto FillPushConstants = [](const ShaderModuleBase* module, PushConstantInfo* info) { diff --git a/src/backend/RenderPipeline.cpp b/src/backend/RenderPipeline.cpp index a0aecca4ee..dd7d06ca3d 100644 --- a/src/backend/RenderPipeline.cpp +++ b/src/backend/RenderPipeline.cpp @@ -89,9 +89,13 @@ namespace backend { // the device if (!mInputState) { mInputState = mDevice->CreateInputStateBuilder()->GetResult(); + // Remove the external ref objects are created with + mInputState->Release(); } if (!mDepthStencilState) { mDepthStencilState = mDevice->CreateDepthStencilStateBuilder()->GetResult(); + // Remove the external ref objects are created with + mDepthStencilState->Release(); } if (!mRenderPass) { HandleError("Pipeline render pass not set"); @@ -109,6 +113,8 @@ namespace backend { for (uint32_t attachmentSlot : IterateBitSet(subpassInfo.colorAttachmentsSet & ~mBlendStatesSet)) { mBlendStates[attachmentSlot] = mDevice->CreateBlendStateBuilder()->GetResult(); + // Remove the external ref objects are created with + mBlendStates[attachmentSlot]->Release(); } return mDevice->CreateRenderPipeline(this);