From d90fad8f5a7fb2a07a721d929d2f9b34deefbdb2 Mon Sep 17 00:00:00 2001 From: ChestnutYueyue <952134128@qq.com> Date: Mon, 16 Mar 2026 18:54:41 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E5=A4=9A=E4=B8=AA?= =?UTF-8?q?=E6=A8=A1=E5=9D=97=E5=85=B3=E9=97=AD=E6=97=B6=E7=9A=84=E9=87=8D?= =?UTF-8?q?=E5=A4=8D=E6=B8=85=E7=90=86=E5=92=8C=E7=8A=B6=E6=80=81=E7=AE=A1?= =?UTF-8?q?=E7=90=86=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在Logger::shutdown()中添加关闭完成日志 - 为RenderGraph添加initialized_状态,防止重复初始化和关闭 - 调整Application关闭日志,明确关闭顺序 - 在GLDevice、CommandQueue、RHIModule的shutdown()中添加状态检查,避免重复清理 - 修复RenderGraph移动构造和移动赋值操作中的状态同步 --- include/renderer/render_graph.h | 1 + src/app/application.cpp | 4 +--- src/renderer/command_queue.cpp | 4 ++++ src/renderer/render_graph.cpp | 16 +++++++++++++++- src/renderer/rhi/opengl/gl_device.cpp | 4 ++++ src/renderer/rhi_module.cpp | 9 +++++---- src/utils/logger.cpp | 1 + 7 files changed, 31 insertions(+), 8 deletions(-) diff --git a/include/renderer/render_graph.h b/include/renderer/render_graph.h index a46e840..f593a22 100644 --- a/include/renderer/render_graph.h +++ b/include/renderer/render_graph.h @@ -296,6 +296,7 @@ private: // 编译状态 bool compiled_ = false; + bool initialized_ = false; /** * @brief 创建内部资源 diff --git a/src/app/application.cpp b/src/app/application.cpp index c9239cb..79ce546 100644 --- a/src/app/application.cpp +++ b/src/app/application.cpp @@ -100,9 +100,7 @@ void Application::shutdown() { initialized_ = false; running_ = false; - - E2D_INFO("应用程序关闭完成"); - + E2D_INFO("应用程序模块关闭完成,准备关闭日志系统"); // 关闭日志系统(在所有日志调用之后) Logger::shutdown(); } diff --git a/src/renderer/command_queue.cpp b/src/renderer/command_queue.cpp index 8b1e266..db5c42f 100644 --- a/src/renderer/command_queue.cpp +++ b/src/renderer/command_queue.cpp @@ -246,6 +246,10 @@ bool CommandQueue::initialize() { } void CommandQueue::shutdown() { + if (!uboManager_ && !commandList_ && !context_) { + return; + } + uboManager_.reset(); commandList_.reset(); context_ = nullptr; diff --git a/src/renderer/render_graph.cpp b/src/renderer/render_graph.cpp index b9a4942..b98a001 100644 --- a/src/renderer/render_graph.cpp +++ b/src/renderer/render_graph.cpp @@ -61,12 +61,14 @@ RenderGraph::RenderGraph(RenderGraph &&other) noexcept builder_(std::move(other.builder_)), commandQueue_(std::move(other.commandQueue_)), outputWidth_(other.outputWidth_), outputHeight_(other.outputHeight_), - frameIndex_(other.frameIndex_), compiled_(other.compiled_) { + frameIndex_(other.frameIndex_), compiled_(other.compiled_), + initialized_(other.initialized_) { other.nextResourceId_ = 1; other.outputWidth_ = 1280; other.outputHeight_ = 720; other.frameIndex_ = 0; other.compiled_ = false; + other.initialized_ = false; } RenderGraph &RenderGraph::operator=(RenderGraph &&other) noexcept { @@ -83,32 +85,44 @@ RenderGraph &RenderGraph::operator=(RenderGraph &&other) noexcept { outputHeight_ = other.outputHeight_; frameIndex_ = other.frameIndex_; compiled_ = other.compiled_; + initialized_ = other.initialized_; other.nextResourceId_ = 1; other.outputWidth_ = 1280; other.outputHeight_ = 720; other.frameIndex_ = 0; other.compiled_ = false; + other.initialized_ = false; } return *this; } bool RenderGraph::initialize() { + if (initialized_) { + return true; + } + if (!commandQueue_.initialize()) { E2D_ERROR("初始化命令队列失败"); return false; } + initialized_ = true; E2D_INFO("渲染图已初始化"); return true; } void RenderGraph::shutdown() { + if (!initialized_) { + return; + } + destroyResources(); passes_.clear(); executionOrder_.clear(); commandQueue_.shutdown(); compiled_ = false; + initialized_ = false; E2D_INFO("渲染图已关闭"); } diff --git a/src/renderer/rhi/opengl/gl_device.cpp b/src/renderer/rhi/opengl/gl_device.cpp index 5ccbca5..d30b8a2 100644 --- a/src/renderer/rhi/opengl/gl_device.cpp +++ b/src/renderer/rhi/opengl/gl_device.cpp @@ -93,6 +93,10 @@ public: } void shutdown() override { + if (!context_ && !glContext_ && !window_) { + return; + } + E2D_INFO("正在关闭 OpenGL 设备..."); if (context_) { diff --git a/src/renderer/rhi_module.cpp b/src/renderer/rhi_module.cpp index 73609f8..bb4f8b0 100644 --- a/src/renderer/rhi_module.cpp +++ b/src/renderer/rhi_module.cpp @@ -87,15 +87,16 @@ void RHIModule::onWindowShow() { } void RHIModule::shutdown() { + if (!initialized_ && !device_ && !context_ && !onShowListener_) { + return; + } + E2D_INFO("正在关闭 RHI模块..."); // 清理事件监听器 onShowListener_.reset(); - if (context_) { - context_->shutdown(); - context_ = nullptr; - } + context_ = nullptr; if (device_) { device_->shutdown(); diff --git a/src/utils/logger.cpp b/src/utils/logger.cpp index d1690f1..da8e470 100644 --- a/src/utils/logger.cpp +++ b/src/utils/logger.cpp @@ -85,6 +85,7 @@ void Logger::shutdown() { #endif } initialized_ = false; + log(LogLevel::Info, "日志系统关闭完成"); } /**