From 0675b182376b0ecd51cff4e5c29bb03f2760807a Mon Sep 17 00:00:00 2001 From: Ian Elliott Date: Mon, 25 Jan 2016 12:33:06 -0700 Subject: [PATCH] Swapchain: Ensure Destroy{Device|Surface}() don't core dump. There are multiple pieces of code that can try to delete an SwpSwapchain struct: - DestroyDevice() - DestroySurface() - DestroySwapchain() This tries to address the various paths through the code, so that Destroy{Device|Surface}() won't also try to destroy an already-destroyed swapchain. --- layers/swapchain.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/layers/swapchain.cpp b/layers/swapchain.cpp index 47e4fe83..f16e4fa6 100644 --- a/layers/swapchain.cpp +++ b/layers/swapchain.cpp @@ -997,6 +997,13 @@ VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroySurfaceKHR(VkInstance insta it != pSurface->swapchains.end() ; it++) { // Delete all SwpImage's it->second->images.clear(); + // In case the swapchain's device hasn't been destroyed yet + // (which isn't likely, but is possible), delete its + // association with this swapchain (i.e. so we can't point to + // this swpchain from that device, later on): + if (it->second->pDevice) { + it->second->pDevice->swapchains.clear(); + } } pSurface->swapchains.clear(); } @@ -1118,6 +1125,13 @@ VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyDevice(VkDevice device, cons it != pDevice->swapchains.end() ; it++) { // Delete all SwpImage's it->second->images.clear(); + // In case the swapchain's surface hasn't been destroyed yet + // (which is likely) delete its association with this swapchain + // (i.e. so we can't point to this swpchain from that surface, + // later on): + if (it->second->pSurface) { + it->second->pSurface->swapchains.clear(); + } } pDevice->swapchains.clear(); } @@ -1864,6 +1878,9 @@ VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroySwapchainKHR( __FUNCTION__); } } + if (pSwapchain->pSurface) { + pSwapchain->pSurface->swapchains.erase(swapchain); + } if (pSwapchain->imageCount) { pSwapchain->images.clear(); } -- 2.34.1