From 1455e793d553b867a5362872d03b4d86a36a6bd5 Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Mon, 22 Jun 2020 15:57:54 +1000 Subject: [PATCH] Vulkan: Fix crash when drag-resizing window --- src/common/vulkan/swap_chain.cpp | 8 ++------ src/frontend-common/vulkan_host_display.cpp | 8 ++++++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/common/vulkan/swap_chain.cpp b/src/common/vulkan/swap_chain.cpp index 30050ef45..52453ee55 100644 --- a/src/common/vulkan/swap_chain.cpp +++ b/src/common/vulkan/swap_chain.cpp @@ -411,12 +411,8 @@ void SwapChain::DestroySwapChain() VkResult SwapChain::AcquireNextImage() { - VkResult res = vkAcquireNextImageKHR(g_vulkan_context->GetDevice(), m_swap_chain, UINT64_MAX, - m_image_available_semaphore, VK_NULL_HANDLE, &m_current_image); - if (res != VK_SUCCESS && res != VK_ERROR_OUT_OF_DATE_KHR && res != VK_SUBOPTIMAL_KHR) - LOG_VULKAN_ERROR(res, "vkAcquireNextImageKHR failed: "); - - return res; + return vkAcquireNextImageKHR(g_vulkan_context->GetDevice(), m_swap_chain, UINT64_MAX, m_image_available_semaphore, + VK_NULL_HANDLE, &m_current_image); } bool SwapChain::ResizeSwapChain(u32 new_width /* = 0 */, u32 new_height /* = 0 */) diff --git a/src/frontend-common/vulkan_host_display.cpp b/src/frontend-common/vulkan_host_display.cpp index f6d2a88ab..399ca3d3f 100644 --- a/src/frontend-common/vulkan_host_display.cpp +++ b/src/frontend-common/vulkan_host_display.cpp @@ -380,9 +380,13 @@ bool VulkanHostDisplay::BeginRender() res = m_swap_chain->AcquireNextImage(); } - if (res != VK_SUCCESS) + // This can happen when multiple resize events happen in quick succession. + // In this case, just wait until the next frame to try again. + if (res != VK_SUCCESS && res != VK_SUBOPTIMAL_KHR) { - Panic("Failed to acquire swap chain image"); + // Still submit the command buffer, otherwise we'll end up with several frames waiting. + LOG_VULKAN_ERROR(res, "vkAcquireNextImageKHR() failed: "); + g_vulkan_context->ExecuteCommandBuffer(false); return false; } }