From e5318d8ea9f8888c47aaf9dfea6f44bc11ef1ff6 Mon Sep 17 00:00:00 2001 From: Benau Date: Tue, 4 Oct 2022 13:55:51 +0800 Subject: [PATCH] Fix crash when minimizing in windows --- lib/graphics_engine/src/ge_vulkan_driver.cpp | 16 +++++++++++++--- src/graphics/irr_driver.cpp | 11 ++++++----- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/lib/graphics_engine/src/ge_vulkan_driver.cpp b/lib/graphics_engine/src/ge_vulkan_driver.cpp index bec282164..8d0a2c9dd 100644 --- a/lib/graphics_engine/src/ge_vulkan_driver.cpp +++ b/lib/graphics_engine/src/ge_vulkan_driver.cpp @@ -1703,8 +1703,8 @@ bool GEVulkanDriver::endScene() return false; } - VkFence fence = m_vk->in_flight_fences[m_current_frame]; - if (vkWaitForFences(m_vk->device, 1, &fence, VK_TRUE, 2000000000) == + if (m_vk->in_flight_fences.empty() || vkWaitForFences(m_vk->device, 1, + &m_vk->in_flight_fences[m_current_frame], VK_TRUE, 2000000000) == VK_TIMEOUT) { // Attempt to restore after out focus in gnome fullscreen @@ -1712,10 +1712,20 @@ bool GEVulkanDriver::endScene() GEVulkan2dRenderer::clear(); handleDeletedTextures(); destroySwapChainRelated(false/*handle_surface*/); - createSwapChainRelated(false/*handle_surface*/); + try + { + createSwapChainRelated(false/*handle_surface*/); + } + catch (std::exception& e) + { + // When minimized in Windows swapchain depth buffer will fail to + // create + destroySwapChainRelated(false/*handle_surface*/); + } return true; } + VkFence fence = m_vk->in_flight_fences[m_current_frame]; vkResetFences(m_vk->device, 1, &fence); vkResetCommandPool(m_vk->device, m_vk->command_pools[m_current_frame], 0); diff --git a/src/graphics/irr_driver.cpp b/src/graphics/irr_driver.cpp index 44856070f..fcffe5928 100644 --- a/src/graphics/irr_driver.cpp +++ b/src/graphics/irr_driver.cpp @@ -2086,16 +2086,17 @@ void IrrDriver::handleWindowResize() new_orientation = (int)SDL_GetDisplayOrientation(0); screen_orientation_changed = m_screen_orientation != new_orientation; #endif - if (m_actual_screen_size != m_video_driver->getCurrentRenderTargetSize() || - current_screen_size != m_video_driver->getCurrentRenderTargetSize() || + const core::dimension2du& new_size = m_video_driver->getCurrentRenderTargetSize(); + if (m_actual_screen_size != new_size || + current_screen_size != new_size || screen_orientation_changed) { - // Don't update when dialog is opened - if (dialog_exists) + // Don't update when dialog is opened or minimized + if (dialog_exists || new_size.getArea() == 0) return; m_screen_orientation = new_orientation; - m_actual_screen_size = m_video_driver->getCurrentRenderTargetSize(); + m_actual_screen_size = new_size; UserConfigParams::m_width = m_actual_screen_size.Width; UserConfigParams::m_height = m_actual_screen_size.Height; UserConfigParams::m_real_width = (unsigned)((float)m_actual_screen_size.Width / m_device->getNativeScaleX());