diff --git a/src/main.c b/src/main.c index e15eec2..447c877 100644 --- a/src/main.c +++ b/src/main.c @@ -1018,6 +1018,7 @@ void createSyncObjects(Application *app) { } void cleanupSwapChain(Application *app) { + for (size_t i = 0; i < app->swapChainFramebufferCount; i++) { vkDestroyFramebuffer(app->device, app->swapChainFramebuffers[i], NULL); } @@ -1026,6 +1027,10 @@ void cleanupSwapChain(Application *app) { vkDestroyImageView(app->device, app->swapChainImageViews[i], NULL); } + free(app->swapChainFramebuffers); + free(app->swapChainImageViews); + free(app->swapChainImages); + vkDestroySwapchainKHR(app->device, app->swapChain, NULL); } @@ -1038,10 +1043,7 @@ void recreateSwapChain(Application *app) { } vkDeviceWaitIdle(app->device); - - free(app->swapChainFramebuffers); - free(app->swapChainImageViews); - free(app->swapChainImages); + cleanupSwapChain(app); createSwapChain(app); createImageViews(app); @@ -1144,9 +1146,6 @@ void mainLoop(Application *app) { void cleanup(Application *app) { cleanupSwapChain(app); - free(app->swapChainFramebuffers); - free(app->swapChainImageViews); - free(app->swapChainImages); for (size_t i = 0; i < MAX_FRAMES_IN_FLIGHT; i++) { vkDestroySemaphore(app->device, app->imageAvailableSemaphores[i], NULL);