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");
|
LOGD("APP_CMD_GAINED_FOCUS");
|
||||||
vulkanExample->focused = true;
|
vulkanExample->focused = true;
|
||||||
break;
|
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__)
|
#elif defined(__linux__)
|
||||||
|
|
|
||||||
|
|
@ -75,14 +75,13 @@ private:
|
||||||
public:
|
public:
|
||||||
VkFormat colorFormat;
|
VkFormat colorFormat;
|
||||||
VkColorSpaceKHR colorSpace;
|
VkColorSpaceKHR colorSpace;
|
||||||
|
/** @brief Handle to the current swap chain, required for recreation */
|
||||||
VkSwapchainKHR swapChain = VK_NULL_HANDLE;
|
VkSwapchainKHR swapChain = VK_NULL_HANDLE;
|
||||||
|
|
||||||
uint32_t imageCount;
|
uint32_t imageCount;
|
||||||
std::vector<VkImage> images;
|
std::vector<VkImage> images;
|
||||||
std::vector<SwapChainBuffer> buffers;
|
std::vector<SwapChainBuffer> buffers;
|
||||||
|
|
||||||
// Index of the deteced graphics and presenting device queue
|
// 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;
|
uint32_t queueNodeIndex = UINT32_MAX;
|
||||||
|
|
||||||
// Creates an os specific surface
|
// Creates an os specific surface
|
||||||
|
|
@ -464,13 +463,21 @@ public:
|
||||||
* Destroy and free Vulkan resources used for the swapchain
|
* Destroy and free Vulkan resources used for the swapchain
|
||||||
*/
|
*/
|
||||||
void cleanup()
|
void cleanup()
|
||||||
|
{
|
||||||
|
if (swapChain != VK_NULL_HANDLE)
|
||||||
{
|
{
|
||||||
for (uint32_t i = 0; i < imageCount; i++)
|
for (uint32_t i = 0; i < imageCount; i++)
|
||||||
{
|
{
|
||||||
vkDestroyImageView(device, buffers[i].view, nullptr);
|
vkDestroyImageView(device, buffers[i].view, nullptr);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
if (surface != VK_NULL_HANDLE)
|
||||||
|
{
|
||||||
fpDestroySwapchainKHR(device, swapChain, nullptr);
|
fpDestroySwapchainKHR(device, swapChain, nullptr);
|
||||||
vkDestroySurfaceKHR(instance, surface, nullptr);
|
vkDestroySurfaceKHR(instance, surface, nullptr);
|
||||||
}
|
}
|
||||||
|
surface = VK_NULL_HANDLE;
|
||||||
|
swapChain = VK_NULL_HANDLE;
|
||||||
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue