Skip to content

Commit

Permalink
vulkan: safer cleanup on shutdown
Browse files Browse the repository at this point in the history
  • Loading branch information
slime73 committed Oct 20, 2024
1 parent a6d29e4 commit d73036f
Showing 1 changed file with 19 additions and 10 deletions.
29 changes: 19 additions & 10 deletions src/modules/graphics/vulkan/Graphics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -324,10 +324,10 @@ void Graphics::submitGpuCommands(SubmitMode submitMode, void *screenshotCallback
VmaAllocation screenshotAllocation = VK_NULL_HANDLE;
VmaAllocationInfo screenshotAllocationInfo = {};

VkImage backbufferImage = fakeBackbuffer != nullptr ? (VkImage)fakeBackbuffer->getHandle() : swapChainImages.at(imageIndex);

if (submitMode == SUBMIT_PRESENT)
{
VkImage backbufferImage = fakeBackbuffer != nullptr ? (VkImage)fakeBackbuffer->getHandle() : swapChainImages.at(imageIndex);

if (pendingScreenshotCallbacks.empty())
{
if (fakeBackbuffer == nullptr)
Expand Down Expand Up @@ -766,7 +766,8 @@ void Graphics::getAPIStats(int &shaderswitches) const

void Graphics::unSetMode()
{
submitGpuCommands(SUBMIT_NOPRESENT);
if (created)
submitGpuCommands(SUBMIT_NOPRESENT);

created = false;

Expand Down Expand Up @@ -3162,14 +3163,22 @@ void Graphics::cleanup()
cleanUpFunctions.clear();

vmaDestroyAllocator(vmaAllocator);
for (size_t i = 0; i < MAX_FRAMES_IN_FLIGHT; i++)
{
vkDestroySemaphore(device, renderFinishedSemaphores[i], nullptr);
vkDestroySemaphore(device, imageAvailableSemaphores[i], nullptr);
vkDestroyFence(device, inFlightFences[i], nullptr);
}

vkFreeCommandBuffers(device, commandPool, MAX_FRAMES_IN_FLIGHT, commandBuffers.data());
for (const auto &s : renderFinishedSemaphores)
vkDestroySemaphore(device, s, nullptr);
renderFinishedSemaphores.clear();

for (const auto &s : imageAvailableSemaphores)
vkDestroySemaphore(device, s, nullptr);
imageAvailableSemaphores.clear();

for (const auto &f : inFlightFences)
vkDestroyFence(device, f, nullptr);
inFlightFences.clear();

if (!commandBuffers.empty())
vkFreeCommandBuffers(device, commandPool, (uint32)commandBuffers.size(), commandBuffers.data());
commandBuffers.clear();

for (auto const &p : samplers)
vkDestroySampler(device, p.second, nullptr);
Expand Down

0 comments on commit d73036f

Please sign in to comment.