From 8eb055ca81ac510c74bab18e4004ae3229593259 Mon Sep 17 00:00:00 2001 From: BZLZHH Date: Sat, 7 Jun 2025 21:14:51 +0800 Subject: [PATCH] [Fix] (Diligent/FrameBuffer): Fix UpdateDefaultFramebuffer crashing. --- .../GL/Framebuffer/GL_Framebuffer.cpp | 32 +++++++++---------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/MG/MG_GL/Implementations/GL/Framebuffer/GL_Framebuffer.cpp b/MG/MG_GL/Implementations/GL/Framebuffer/GL_Framebuffer.cpp index ea25b695..45b98b73 100644 --- a/MG/MG_GL/Implementations/GL/Framebuffer/GL_Framebuffer.cpp +++ b/MG/MG_GL/Implementations/GL/Framebuffer/GL_Framebuffer.cpp @@ -45,22 +45,19 @@ namespace MG_GL::GL { MG_Util::Debug::LogE("CreateRenderPassAndFramebuffer: Swap chain not initialized for default framebuffer"); return; } - } - else { - if (!fbInfo.ColorRTVs.empty() && fbInfo.ColorRTVs[0]) { - const auto& desc = fbInfo.ColorRTVs[0]->GetTexture()->GetDesc(); - width = desc.Width; - height = desc.Height; - MG_Util::Debug::LogD("CreateRenderPassAndFramebuffer: Using color attachment 0 for dimensions: %ux%u", width, height); - } else if (fbInfo.pDepthStencilRTV) { - const auto& desc = fbInfo.pDepthStencilRTV->GetTexture()->GetDesc(); - width = desc.Width; - height = desc.Height; - MG_Util::Debug::LogD("CreateRenderPassAndFramebuffer: Using depth/stencil attachment for dimensions: %ux%u", width, height); - } else { - MG_Util::Debug::LogE("CreateRenderPassAndFramebuffer: Failed to determine framebuffer dimensions. No attachments."); - return; - } + } else if (!fbInfo.ColorRTVs.empty() && fbInfo.ColorRTVs[0]) { + const auto& desc = fbInfo.ColorRTVs[0]->GetTexture()->GetDesc(); + width = desc.Width; + height = desc.Height; + MG_Util::Debug::LogD("CreateRenderPassAndFramebuffer: Using color attachment 0 for dimensions: %ux%u", width, height); + } else if (fbInfo.pDepthStencilRTV) { + const auto& desc = fbInfo.pDepthStencilRTV->GetTexture()->GetDesc(); + width = desc.Width; + height = desc.Height; + MG_Util::Debug::LogD("CreateRenderPassAndFramebuffer: Using depth/stencil attachment for dimensions: %ux%u", width, height); + } else { + MG_Util::Debug::LogE("CreateRenderPassAndFramebuffer: Failed to determine framebuffer dimensions. No attachments."); + return; } if (width == 0 || height == 0) { @@ -76,7 +73,8 @@ namespace MG_GL::GL { for (size_t i = 0; i < fbInfo.ColorRTVs.size(); ++i) { if (fbInfo.ColorRTVs[i]) { Diligent::RenderPassAttachmentDesc ColorAttachment; - ColorAttachment.Format = fbInfo.ColorRTVs[i]->GetDesc().Format; + ColorAttachment.Format = framebuffer != 0 ? fbInfo.ColorRTVs[i]->GetDesc().Format: + MG_Diligent::g_pSwapChain->GetDesc().ColorBufferFormat; ColorAttachment.SampleCount = 1; ColorAttachment.InitialState = Diligent::RESOURCE_STATE_RENDER_TARGET; ColorAttachment.FinalState = Diligent::RESOURCE_STATE_RENDER_TARGET;