From 128302d7268750084865d574483bd4ba90c7f25e Mon Sep 17 00:00:00 2001 From: Jupeyy Date: Fri, 10 May 2024 18:00:50 +0200 Subject: [PATCH] Cleanup Vulkan now takes `SwapchainCount` as explicit parameter. This fixes a crash if the swapchain count changed. fixes #8328 --- .../client/backend/vulkan/backend_vulkan.cpp | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/engine/client/backend/vulkan/backend_vulkan.cpp b/src/engine/client/backend/vulkan/backend_vulkan.cpp index 131ab3850..1ad571b6a 100644 --- a/src/engine/client/backend/vulkan/backend_vulkan.cpp +++ b/src/engine/client/backend/vulkan/backend_vulkan.cpp @@ -5374,6 +5374,8 @@ public: m_vFrameFences.clear(); m_vImagesFences.clear(); + + m_CurFrameSyncObject = 0; } void DestroyBufferOfFrame(size_t ImageIndex, SFrameBuffers &Buffer) @@ -5427,7 +5429,7 @@ public: } template - void CleanupVulkan() + void CleanupVulkan(size_t SwapchainCount) { if(IsLastCleanup) { @@ -5465,7 +5467,7 @@ public: m_vStreamedVertexBuffers.clear(); m_vStreamedUniformBuffers.clear(); - for(size_t i = 0; i < m_SwapChainImageCount; ++i) + for(size_t i = 0; i < SwapchainCount; ++i) { ClearFrameData(i); } @@ -5474,11 +5476,11 @@ public: m_vvFrameDelayedTextureCleanup.clear(); m_vvFrameDelayedTextTexturesCleanup.clear(); - m_StagingBufferCache.DestroyFrameData(m_SwapChainImageCount); - m_StagingBufferCacheImage.DestroyFrameData(m_SwapChainImageCount); - m_VertexBufferCache.DestroyFrameData(m_SwapChainImageCount); + m_StagingBufferCache.DestroyFrameData(SwapchainCount); + m_StagingBufferCacheImage.DestroyFrameData(SwapchainCount); + m_VertexBufferCache.DestroyFrameData(SwapchainCount); for(auto &ImageBufferCache : m_ImageBufferCaches) - ImageBufferCache.second.DestroyFrameData(m_SwapChainImageCount); + ImageBufferCache.second.DestroyFrameData(SwapchainCount); if(IsLastCleanup) { @@ -5556,7 +5558,7 @@ public: if(OldSwapChainImageCount != m_SwapChainImageCount) { - CleanupVulkan(); + CleanupVulkan(OldSwapChainImageCount); InitVulkan(); } @@ -6620,7 +6622,7 @@ public: DestroyIndexBuffer(m_IndexBuffer, m_IndexBufferMemory); DestroyIndexBuffer(m_RenderIndexBuffer, m_RenderIndexBufferMemory); - CleanupVulkan(); + CleanupVulkan(m_SwapChainImageCount); return true; }