Swapchain (and surface) cleanup on APP_CMD_TERM_WINDOW (Android)
This commit is contained in:
parent
b7ca1aad5d
commit
5862dc0479
2 changed files with 20 additions and 8 deletions
|
|
@ -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__)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
@ -464,13 +463,21 @@ public:
|
|||
* Destroy and free Vulkan resources used for the swapchain
|
||||
*/
|
||||
void cleanup()
|
||||
{
|
||||
if (swapChain != VK_NULL_HANDLE)
|
||||
{
|
||||
for (uint32_t i = 0; i < imageCount; i++)
|
||||
{
|
||||
vkDestroyImageView(device, buffers[i].view, nullptr);
|
||||
}
|
||||
}
|
||||
if (surface != VK_NULL_HANDLE)
|
||||
{
|
||||
fpDestroySwapchainKHR(device, swapChain, nullptr);
|
||||
vkDestroySurfaceKHR(instance, surface, nullptr);
|
||||
}
|
||||
surface = VK_NULL_HANDLE;
|
||||
swapChain = VK_NULL_HANDLE;
|
||||
}
|
||||
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue