Skip to content

Commit

Permalink
Cleanup Vulkan now takes SwapchainCount as explicit parameter.
Browse files Browse the repository at this point in the history
This fixes a crash if the swapchain count changed.
fixes ddnet#8328
  • Loading branch information
Jupeyy committed May 10, 2024
1 parent 609596f commit 586f607
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions src/engine/client/backend/vulkan/backend_vulkan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5374,6 +5374,8 @@ class CCommandProcessorFragment_Vulkan : public CCommandProcessorFragment_GLBase

m_vFrameFences.clear();
m_vImagesFences.clear();

m_CurFrameSyncObject = 0;
}

void DestroyBufferOfFrame(size_t ImageIndex, SFrameBuffers &Buffer)
Expand Down Expand Up @@ -5427,7 +5429,7 @@ class CCommandProcessorFragment_Vulkan : public CCommandProcessorFragment_GLBase
}

template<bool IsLastCleanup>
void CleanupVulkan()
void CleanupVulkan(size_t SwapchainCount)
{
if(IsLastCleanup)
{
Expand Down Expand Up @@ -5465,7 +5467,7 @@ class CCommandProcessorFragment_Vulkan : public CCommandProcessorFragment_GLBase
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);
}
Expand All @@ -5474,11 +5476,11 @@ class CCommandProcessorFragment_Vulkan : public CCommandProcessorFragment_GLBase
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)
{
Expand Down Expand Up @@ -5556,7 +5558,7 @@ class CCommandProcessorFragment_Vulkan : public CCommandProcessorFragment_GLBase

if(OldSwapChainImageCount != m_SwapChainImageCount)
{
CleanupVulkan<false>();
CleanupVulkan<false>(OldSwapChainImageCount);
InitVulkan<false>();
}

Expand Down Expand Up @@ -6620,7 +6622,7 @@ class CCommandProcessorFragment_Vulkan : public CCommandProcessorFragment_GLBase
DestroyIndexBuffer(m_IndexBuffer, m_IndexBufferMemory);
DestroyIndexBuffer(m_RenderIndexBuffer, m_RenderIndexBufferMemory);

CleanupVulkan<true>();
CleanupVulkan<true>(m_SwapChainImageCount);

return true;
}
Expand Down

0 comments on commit 586f607

Please sign in to comment.