Swapchain (and surface) cleanup on APP_CMD_TERM_WINDOW (Android)

This commit is contained in:
saschawillems 2016-08-31 20:41:32 +02:00
parent b7ca1aad5d
commit 5862dc0479
2 changed files with 20 additions and 8 deletions

View file

@ -1205,6 +1205,11 @@ void VulkanExampleBase::handleAppCommand(android_app * app, int32_t cmd)
LOGD("APP_CMD_GAINED_FOCUS");
vulkanExample->focused = true;
break;
case APP_CMD_TERM_WINDOW:
// Window is hidden or closed, clean up resources
LOGD("APP_CMD_TERM_WINDOW");
vulkanExample->swapChain.cleanup();
break;
}
}
#elif defined(__linux__)

View file

@ -75,14 +75,13 @@ private:
public:
VkFormat colorFormat;
VkColorSpaceKHR colorSpace;
/** @brief Handle to the current swap chain, required for recreation */
VkSwapchainKHR swapChain = VK_NULL_HANDLE;
uint32_t imageCount;
std::vector<VkImage> images;
std::vector<SwapChainBuffer> buffers;
// Index of the deteced graphics and presenting device queue
/** @brief Queue family index of the deteced graphics and presenting device queue */
uint32_t queueNodeIndex = UINT32_MAX;
// Creates an os specific surface
@ -465,12 +464,20 @@ public:
*/
void cleanup()
{
for (uint32_t i = 0; i < imageCount; i++)
if (swapChain != VK_NULL_HANDLE)
{
vkDestroyImageView(device, buffers[i].view, nullptr);
for (uint32_t i = 0; i < imageCount; i++)
{
vkDestroyImageView(device, buffers[i].view, nullptr);
}
}
fpDestroySwapchainKHR(device, swapChain, nullptr);
vkDestroySurfaceKHR(instance, surface, nullptr);
if (surface != VK_NULL_HANDLE)
{
fpDestroySwapchainKHR(device, swapChain, nullptr);
vkDestroySurfaceKHR(instance, surface, nullptr);
}
surface = VK_NULL_HANDLE;
swapChain = VK_NULL_HANDLE;
}
};