Skip to content

Commit 8027a06

Browse files
fix nasty memory leaks
1 parent a55cbe6 commit 8027a06

File tree

5 files changed

+22
-5
lines changed

5 files changed

+22
-5
lines changed

include/nbl/video/surface/CSurfaceVulkan.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class NBL_API2 ISurfaceVulkan : public ISurface
2828

2929
protected:
3030
explicit inline ISurfaceVulkan(core::smart_refctd_ptr<video::IAPIConnection>&& api, VkSurfaceKHR vk_surface) : base_t(std::move(api)), m_vkSurfaceKHR(vk_surface) {}
31-
virtual ~ISurfaceVulkan() = default;
31+
virtual ~ISurfaceVulkan();
3232

3333
VkSurfaceKHR m_vkSurfaceKHR = VK_NULL_HANDLE;
3434
};

src/nbl/video/CSurfaceVulkan.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,12 @@ bool ISurfaceVulkan::isSupportedForPhysicalDevice(const IPhysicalDevice* physica
119119
return true;
120120
}
121121

122+
ISurfaceVulkan::~ISurfaceVulkan()
123+
{
124+
vkDestroySurfaceKHR(static_cast<video::CVulkanConnection*>(m_api.get())->getInternalObject(),m_vkSurfaceKHR,nullptr);
125+
}
126+
127+
122128
#ifdef _NBL_PLATFORM_WINDOWS_
123129
core::smart_refctd_ptr<CSurfaceVulkanWin32> CSurfaceVulkanWin32::create(core::smart_refctd_ptr<video::CVulkanConnection>&& api, core::smart_refctd_ptr<ui::IWindowWin32>&& window)
124130
{

src/nbl/video/CVulkanBuffer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace nbl::video
88
CVulkanBuffer::~CVulkanBuffer()
99
{
1010
preDestroyStep();
11-
if (m_cachedCreationParams.skipHandleDestroy)
11+
if (!m_cachedCreationParams.skipHandleDestroy)
1212
{
1313
const CVulkanLogicalDevice* vulkanDevice = static_cast<const CVulkanLogicalDevice*>(getOriginDevice());
1414
auto* vk = vulkanDevice->getFunctionTable();

src/nbl/video/CVulkanLogicalDevice.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,17 @@ m_vkdev(vkdev), m_devf(vkdev), m_deferred_op_mempool(NODES_PER_BLOCK_DEFERRED_OP
4141
}
4242
}
4343

44-
m_dummyDSLayout = createDescriptorSetLayout({});
44+
{
45+
const VkDescriptorSetLayoutCreateInfo vk_createInfo = {
46+
.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO,
47+
.pNext = nullptr,
48+
.flags = 0,
49+
.bindingCount = 0,
50+
.pBindings = nullptr
51+
};
52+
const bool success = m_devf.vk.vkCreateDescriptorSetLayout(m_vkdev,&vk_createInfo,nullptr,&m_dummyDSLayout)==VK_SUCCESS;
53+
assert(success);
54+
}
4555
}
4656

4757

@@ -569,7 +579,7 @@ core::smart_refctd_ptr<IGPUPipelineLayout> CVulkanLogicalDevice::createPipelineL
569579
{
570580
if (tmp[i])
571581
nonNullSetLayoutCount = i;
572-
vk_dsLayouts[i] = static_cast<const CVulkanDescriptorSetLayout*>((tmp[i] ? tmp[i]:m_dummyDSLayout).get())->getInternalObject();
582+
vk_dsLayouts[i] = tmp[i] ? static_cast<const CVulkanDescriptorSetLayout*>(tmp[i].get())->getInternalObject():m_dummyDSLayout;
573583
}
574584
nonNullSetLayoutCount++;
575585

src/nbl/video/CVulkanLogicalDevice.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ class CVulkanLogicalDevice final : public ILogicalDevice
9191
private:
9292
inline ~CVulkanLogicalDevice()
9393
{
94+
m_devf.vk.vkDestroyDescriptorSetLayout(m_vkdev,m_dummyDSLayout,nullptr);
9495
m_devf.vk.vkDestroyDevice(m_vkdev,nullptr);
9596
}
9697

@@ -315,7 +316,7 @@ class CVulkanLogicalDevice final : public ILogicalDevice
315316
constexpr static inline uint32_t MAX_BLOCK_COUNT_DEFERRED_OP = 256u;
316317
memory_pool_mt_t m_deferred_op_mempool;
317318

318-
core::smart_refctd_ptr<video::IGPUDescriptorSetLayout> m_dummyDSLayout = nullptr;
319+
VkDescriptorSetLayout m_dummyDSLayout;
319320
};
320321

321322
}

0 commit comments

Comments
 (0)