From 2b255751b6bcca4e4271035ac0a4ac6928a4deae Mon Sep 17 00:00:00 2001 From: ssdfasd <2156608475@qq.com> Date: Sat, 28 Mar 2026 17:16:25 +0800 Subject: [PATCH] fix: avoid editor viewport resize deadlock --- editor/src/Application.cpp | 4 ++++ editor/src/Platform/D3D12WindowRenderer.h | 20 +++++++++++++++++--- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/editor/src/Application.cpp b/editor/src/Application.cpp index cdc04b63..18beaeea 100644 --- a/editor/src/Application.cpp +++ b/editor/src/Application.cpp @@ -96,6 +96,10 @@ void Application::ShutdownEditorContext() { void Application::RenderEditorFrame() { static constexpr float kClearColor[4] = { 0.22f, 0.22f, 0.22f, 1.0f }; + if (!m_windowRenderer.BeginFrame()) { + return; + } + m_imguiBackend.BeginFrame(); m_viewportHostService.BeginFrame(); m_layerStack.onImGuiRender(); diff --git a/editor/src/Platform/D3D12WindowRenderer.h b/editor/src/Platform/D3D12WindowRenderer.h index 3ce7b935..04176cfa 100644 --- a/editor/src/Platform/D3D12WindowRenderer.h +++ b/editor/src/Platform/D3D12WindowRenderer.h @@ -155,6 +155,23 @@ public: RecreateBackBufferViews(); } + bool BeginFrame() { + auto* d3d12Queue = GetD3D12CommandQueue(); + auto* d3d12CommandList = GetD3D12CommandList(); + if (m_swapChain == nullptr || + d3d12Queue == nullptr || + d3d12CommandList == nullptr || + m_srvHeap == nullptr) { + return false; + } + + // Viewport panels can resize and recreate render targets while building ImGui. + // Make sure the previous frame is fully retired before any CPU-side resource destruction. + d3d12Queue->WaitForPreviousFrame(); + m_commandList->Reset(); + return true; + } + void Render( UI::ImGuiBackendBridge& imguiBackend, const float clearColor[4], @@ -168,9 +185,6 @@ public: return; } - d3d12Queue->WaitForPreviousFrame(); - m_commandList->Reset(); - if (beforeUiRender) { beforeUiRender(GetRenderContext()); }