From e70ede130d773b50c70e9a5adad58a90e359c259 Mon Sep 17 00:00:00 2001 From: Matteo De Carlo Date: Tue, 9 Nov 2021 17:59:08 +0100 Subject: [PATCH] Fixed crash on wayland exit (#352) The engine would crash on exit because SDL handles the deletion of the swapchain on his own, making the engine delete the swapchain twice, which would result in a crash on wayland. This fix checks if the Video Subsystem is not running any more, if not it will assume there is no need to destroy the swap chains any more. --- WickedEngine/wiGraphicsDevice_Vulkan.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/WickedEngine/wiGraphicsDevice_Vulkan.cpp b/WickedEngine/wiGraphicsDevice_Vulkan.cpp index 5c4ef3eb7..88c9057d0 100644 --- a/WickedEngine/wiGraphicsDevice_Vulkan.cpp +++ b/WickedEngine/wiGraphicsDevice_Vulkan.cpp @@ -924,8 +924,15 @@ namespace Vulkan_Internal vkDestroyFramebuffer(allocationhandler->device, swapChainFramebuffers[i], nullptr); vkDestroyImageView(allocationhandler->device, swapChainImageViews[i], nullptr); } - vkDestroySwapchainKHR(allocationhandler->device, swapChain, nullptr); - vkDestroySurfaceKHR(allocationhandler->instance, surface, nullptr); + #ifdef SDL2 + // Checks if the SDL VIDEO System was already destroyed. + // If so we would delete the swapchain twice, causing a crash on wayland. + if (SDL_WasInit(SDL_INIT_VIDEO)) + #endif + { + vkDestroySwapchainKHR(allocationhandler->device, swapChain, nullptr); + vkDestroySurfaceKHR(allocationhandler->instance, surface, nullptr); + } vkDestroySemaphore(allocationhandler->device, swapchainAcquireSemaphore, nullptr); vkDestroySemaphore(allocationhandler->device, swapchainReleaseSemaphore, nullptr);