Vulkan Swapchain Recreation

I am very new to Vulkan and I’ve been having trouble with window resizing. I have two classes: Renderer and Canvas. Canvas is a wrapper around Swapchain, its images, image views, and framebuffers. Renderer is currently responsible for drawing to the screen. The swapchain builds fine on startup and a triangle appears as it should: However, whenever I resize the window, the result of a vkQueuePresentKHR() returns VK_ERROR_OUT_OF_DATE_KHR over and over again, even though I recreate the swapchain. The rendered image does not spread over to the new surface: The code for recreating the swapchain is simple, it destroys any dependent objects (render pass, graphics pipeline, and the whole canvas wrapper) and calls the same creation methods that were used to start up the application. Here it is for reference: FResult Renderer::recreateRenderTarget() { int width = 0, height = 0; // if minimized while (width == 0 || height == 0) { glfwGetFramebufferSize(m_canvas->getWindow(), &width, &height); glfwWaitEvents(); // wait until the next batch of events are triggered } vkDeviceWaitIdle(m_logicalDevice); // Make sure there aren’t any resources in use by waiting for any async actions to finish vkDestroyPipeline(m_logicalDevice, m_graphicsPipeline, nullptr); vkDestroyPipelineLayout(m_logicalDevice, m_pipelineLayout, nullptr); vkDestroyRenderPass(m_logicalDevice, m_renderPass, nullptr); m_canvas->destroySwapchain(); if (m_canvas->initializeSwapchain() != FResult::Success) { CLOG_ERROR(LogCategory::Graphics, “Failed to recreate swapchain”); return FResult::Error; } else if (createRenderPass() != FResult::Success) { CLOG_ERROR(LogCategory::Graphics, “Failed to recreate render pass”); return FResult::Error; } else if (createPipeline() != FResult::Success) { CLOG_ERROR(LogCategory::Graphics, “Failed to recreate pipeline”); return FResult::Error; } else if (m_canvas->initializeFramebuffers(m_renderPass) != FResult::Success) { CLOG_ERROR(LogCategory::Graphics, “Failed to recreate framebuffers”); return FResult::Error; } else if (record() != FResult::Success) { CLOG_ERROR(LogCategory::Graphics, “Failed to record to command buffer”); return FResult::Error; } else { CLOG_INFO(LogCategory::Graphics, “Recreated swapchain”); return FResult::Success; } } The canvas object’s destroySwapchain() method destroys the framebuffers, the image views, then the swapchain itself. Nevertheless, it does not seem to work and the validation layers aren’t reporting anything wrong. This recreateRenderTarget() method itself runs upon resize and return successfully, however since the result of the queue submit is an out of date swapchain, it then runs indefinitely over and over again. I must be making a simple mistake somewhere, but I can’t seem to figure out where, and any help would be greatly appreciated. I’m not too sure if any further details are needed but I’ll supply if asked.

Published by CelleSports

CelleSports is a Game development, News outlet, and Social Cell community. Build your cells or teams for any game and start communicating efficiently. Join us in building the number one eSport and gaming community in the World. Join Cell eSports

Leave a comment