mirror of
https://github.com/charles-lunarg/vk-bootstrap.git
synced 2024-11-22 07:24:34 +00:00
Document proper swapchain recreation practice
Make the example not leak the old swapchain handle upon recreation. vkb::destroy_swapchain doesn't null out the old handle.
This commit is contained in:
parent
d169f3e32d
commit
bbe3971a04
@ -247,7 +247,9 @@ if !(swap_ret){
|
||||
// If it failed to create a swapchain, the old swapchain handle is invalid.
|
||||
vkb_swapchain.swapchain = VK_NULL_HANDLE;
|
||||
}
|
||||
// Note that this is the same vkb::Swapchain which was fed into vkb::SwapchainBuilder
|
||||
// Even though we recycled the previous swapchain, we need to free its resources.
|
||||
vkb::destroy_swapchain(vkb_swapchain);
|
||||
// Get the new swapchain and place it in our variable
|
||||
vkb_swapchain = swap_ret.value();
|
||||
```
|
||||
|
||||
|
@ -73,17 +73,12 @@ int device_initialization (Init& init) {
|
||||
int create_swapchain (Init& init) {
|
||||
|
||||
vkb::SwapchainBuilder swapchain_builder{ init.device };
|
||||
auto swap_ret = swapchain_builder
|
||||
.set_old_swapchain (init.swapchain)
|
||||
.build ();
|
||||
static int count = 0;
|
||||
count++;
|
||||
std::cout << count << '\n';
|
||||
auto swap_ret = swapchain_builder.set_old_swapchain (init.swapchain).build ();
|
||||
if (!swap_ret) {
|
||||
std::cout << swap_ret.error ().message () << " " << swap_ret.vk_result () << "\n";
|
||||
init.swapchain.swapchain = VK_NULL_HANDLE;
|
||||
return -1;
|
||||
}
|
||||
vkb::destroy_swapchain(init.swapchain);
|
||||
init.swapchain = swap_ret.value ();
|
||||
return 0;
|
||||
}
|
||||
|
@ -1292,10 +1292,10 @@ VkExtent2D find_extent (
|
||||
}
|
||||
} // namespace detail
|
||||
|
||||
void destroy_swapchain (Swapchain& swapchain) {
|
||||
void destroy_swapchain (Swapchain const& swapchain) {
|
||||
if (swapchain.device != VK_NULL_HANDLE && swapchain.swapchain != VK_NULL_HANDLE) {
|
||||
vkDestroySwapchainKHR (swapchain.device, swapchain.swapchain, swapchain.allocation_callbacks);
|
||||
swapchain.swapchain = VK_NULL_HANDLE;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -528,7 +528,7 @@ struct Swapchain {
|
||||
void destroy_image_views (std::vector<VkImageView> const& image_views);
|
||||
};
|
||||
|
||||
void destroy_swapchain (Swapchain & swapchain);
|
||||
void destroy_swapchain (Swapchain const& swapchain);
|
||||
|
||||
class SwapchainBuilder {
|
||||
public:
|
||||
|
@ -15,7 +15,7 @@ GLFWwindow* create_window_glfw (const char * window_name = "", bool resize = tru
|
||||
glfwWindowHint (GLFW_CLIENT_API, GLFW_NO_API);
|
||||
if (!resize) glfwWindowHint (GLFW_RESIZABLE, GLFW_FALSE);
|
||||
|
||||
return glfwCreateWindow (640, 480, window_name, NULL, NULL);
|
||||
return glfwCreateWindow (1024,1024, window_name, NULL, NULL);
|
||||
}
|
||||
void destroy_window_glfw (GLFWwindow* window) {
|
||||
glfwDestroyWindow (window);
|
||||
|
Loading…
Reference in New Issue
Block a user