11#include " renderer.h"
22#include " imgui_system.h"
3+ #include " imgui/imgui.h"
34#include < fstream>
45#include < stdexcept>
56#include < array>
@@ -246,6 +247,23 @@ void Renderer::cleanupSwapChain() {
246247 // Clean up swap chain image views
247248 swapChainImageViews.clear ();
248249
250+ // Clean up descriptor pool (this will automatically clean up descriptor sets)
251+ descriptorPool = nullptr ;
252+
253+ // Clean up pipelines
254+ graphicsPipeline = nullptr ;
255+ pbrGraphicsPipeline = nullptr ;
256+ lightingPipeline = nullptr ;
257+
258+ // Clean up pipeline layouts
259+ pipelineLayout = nullptr ;
260+ pbrPipelineLayout = nullptr ;
261+ lightingPipelineLayout = nullptr ;
262+
263+ // Clean up sync objects (they need to be recreated with new swap chain image count)
264+ imageAvailableSemaphores.clear ();
265+ renderFinishedSemaphores.clear ();
266+
249267 // Clean up swap chain
250268 swapChain = nullptr ;
251269}
@@ -258,10 +276,15 @@ void Renderer::recreateSwapChain() {
258276 // Clean up old swap chain resources
259277 cleanupSwapChain ();
260278
261- // Recreate swap chain
279+ // Recreate swap chain and related resources
262280 createSwapChain ();
263281 createImageViews ();
264282 createDepthResources ();
283+
284+ // Recreate sync objects with correct sizing for new swap chain
285+ createSyncObjects ();
286+
287+ // Recreate descriptor pool and pipelines
265288 createDescriptorPool ();
266289 createGraphicsPipeline ();
267290 createPBRPipeline ();
@@ -314,6 +337,12 @@ void Renderer::Render(const std::vector<Entity*>& entities, CameraComponent* cam
314337 // Check if the swap chain needs to be recreated
315338 if (result.first == vk::Result::eErrorOutOfDateKHR || result.first == vk::Result::eSuboptimalKHR || framebufferResized) {
316339 framebufferResized = false ;
340+
341+ // If ImGui has started a frame, we need to end it properly before returning
342+ if (imguiSystem) {
343+ ImGui::EndFrame ();
344+ }
345+
317346 recreateSwapChain ();
318347 return ;
319348 } else if (result.first != vk::Result::eSuccess) {
0 commit comments