Skip to content

Commit 95929f4

Browse files
authored
Destroy_Functions_and_Resizing_Error (#95)
* Resizing_Error * Destroy functions
1 parent 2ac127f commit 95929f4

File tree

8 files changed

+20
-3
lines changed

8 files changed

+20
-3
lines changed

HelloVulkan/Header/Vulkan/VulkanBuffer.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ class VulkanBuffer
3636
if (vmaAllocation_)
3737
{
3838
vmaDestroyBuffer(vmaAllocator_, buffer_, vmaAllocation_);
39+
buffer_ = nullptr;
40+
vmaAllocation_ = nullptr;
3941
}
4042
}
4143

HelloVulkan/Source/Apps/AppBase.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,9 @@ void AppBase::ProcessInput()
368368

369369
void AppBase::InitSharedResources()
370370
{
371-
resShared_ = std::make_unique<ResourcesShared>();
371+
if (!resShared_)
372+
{
373+
resShared_ = std::make_unique<ResourcesShared>();
374+
}
372375
resShared_->Create(vulkanContext_);
373376
}

HelloVulkan/Source/Vulkan/VulkanAccelStructure.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,13 @@ void VulkanAccelStructure::Destroy()
3333
if (vmaAllocation_)
3434
{
3535
vmaDestroyBuffer(vmaAllocator_, buffer_, vmaAllocation_);
36+
buffer_ = nullptr;
37+
vmaAllocation_ = nullptr;
3638
}
3739

3840
if (handle_)
3941
{
4042
vkDestroyAccelerationStructureKHR(device_, handle_, nullptr);
43+
handle_ = nullptr;
4144
}
4245
}

HelloVulkan/Source/Vulkan/VulkanDescriptor.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,11 +193,13 @@ void VulkanDescriptor::Destroy()
193193
if (layout_)
194194
{
195195
vkDestroyDescriptorSetLayout(device_, layout_, nullptr);
196+
layout_ = nullptr;
196197
}
197198

198199
if (pool_)
199200
{
200201
vkDestroyDescriptorPool(device_, pool_, nullptr);
202+
pool_ = nullptr;
201203
}
202204
}
203205

HelloVulkan/Source/Vulkan/VulkanFramebuffer.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,10 @@ void VulkanFramebuffer::CreateUnresizeable(
6464

6565
void VulkanFramebuffer::Destroy()
6666
{
67-
for (VkFramebuffer& f : framebuffers_)
67+
for (size_t i = 0; i < framebuffers_.size(); ++i)
6868
{
69-
vkDestroyFramebuffer(device_, f, nullptr);
69+
vkDestroyFramebuffer(device_, framebuffers_[i], nullptr);
70+
framebuffers_[i] = nullptr;
7071
}
7172
// NOTE Don't clear because we may recreate
7273
//framebuffers_.clear();

HelloVulkan/Source/Vulkan/VulkanImage.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,20 @@ void VulkanImage::Destroy()
1212
if (defaultImageSampler_)
1313
{
1414
vkDestroySampler(device_, defaultImageSampler_, nullptr);
15+
defaultImageSampler_ = nullptr;
1516
}
1617

1718
if (imageView_)
1819
{
1920
vkDestroyImageView(device_, imageView_, nullptr);
21+
imageView_ = nullptr;
2022
}
2123

2224
if (vmaAllocation_)
2325
{
2426
vmaDestroyImage(vmaAllocator_, image_, vmaAllocation_);
27+
image_ = nullptr;
28+
vmaAllocation_ = nullptr;
2529
}
2630
}
2731

HelloVulkan/Source/Vulkan/VulkanRenderPass.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -577,5 +577,6 @@ void VulkanRenderPass::Destroy()
577577
if (handle_)
578578
{
579579
vkDestroyRenderPass(device_, handle_, nullptr);
580+
handle_ = nullptr;
580581
}
581582
}

HelloVulkan/Source/Vulkan/VulkanShader.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ void VulkanShader::Destroy()
3838
if (shaderModule_)
3939
{
4040
vkDestroyShaderModule(device_, shaderModule_, nullptr);
41+
shaderModule_ = nullptr;
4142
}
4243
}
4344

0 commit comments

Comments
 (0)