diff --git a/docs/getting_started.md b/docs/getting_started.md index ff929bd..a0c8563 100644 --- a/docs/getting_started.md +++ b/docs/getting_started.md @@ -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(); ``` diff --git a/example/triangle.cpp b/example/triangle.cpp index 3344ee0..c08ebe3 100644 --- a/example/triangle.cpp +++ b/example/triangle.cpp @@ -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; + std::cout << swap_ret.error ().message () << " " << swap_ret.vk_result () << "\n"; + return -1; } + vkb::destroy_swapchain(init.swapchain); init.swapchain = swap_ret.value (); return 0; } @@ -439,13 +434,13 @@ int recreate_swapchain (Init& init, RenderData& data) { vkDestroyCommandPool (init.device.device, data.command_pool, nullptr); - for (auto framebuffer : data.framebuffers) { - vkDestroyFramebuffer (init.device.device, framebuffer, nullptr); - } - + for (auto framebuffer : data.framebuffers) { + vkDestroyFramebuffer (init.device.device, framebuffer, nullptr); + } + init.swapchain.destroy_image_views (data.swapchain_image_views); - if (0 != create_swapchain (init)) return -1; + if (0 != create_swapchain (init)) return -1; if (0 != create_framebuffers (init, data)) return -1; if (0 != create_command_pool (init, data)) return -1; if (0 != create_command_buffers (init, data)) return -1; diff --git a/src/VkBootstrap.cpp b/src/VkBootstrap.cpp index cffaaeb..6f7dd13 100644 --- a/src/VkBootstrap.cpp +++ b/src/VkBootstrap.cpp @@ -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; + } } diff --git a/src/VkBootstrap.h b/src/VkBootstrap.h index d939d7d..d7abb3f 100644 --- a/src/VkBootstrap.h +++ b/src/VkBootstrap.h @@ -528,7 +528,7 @@ struct Swapchain { void destroy_image_views (std::vector const& image_views); }; -void destroy_swapchain (Swapchain & swapchain); +void destroy_swapchain (Swapchain const& swapchain); class SwapchainBuilder { public: diff --git a/tests/common.h b/tests/common.h index 6dfbba1..ead0448 100644 --- a/tests/common.h +++ b/tests/common.h @@ -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);