fix: 修复多个模块关闭时的重复清理和状态管理问题
- 在Logger::shutdown()中添加关闭完成日志 - 为RenderGraph添加initialized_状态,防止重复初始化和关闭 - 调整Application关闭日志,明确关闭顺序 - 在GLDevice、CommandQueue、RHIModule的shutdown()中添加状态检查,避免重复清理 - 修复RenderGraph移动构造和移动赋值操作中的状态同步
This commit is contained in:
parent
2b552347fe
commit
d90fad8f5a
|
|
@ -296,6 +296,7 @@ private:
|
||||||
|
|
||||||
// 编译状态
|
// 编译状态
|
||||||
bool compiled_ = false;
|
bool compiled_ = false;
|
||||||
|
bool initialized_ = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief 创建内部资源
|
* @brief 创建内部资源
|
||||||
|
|
|
||||||
|
|
@ -100,9 +100,7 @@ void Application::shutdown() {
|
||||||
|
|
||||||
initialized_ = false;
|
initialized_ = false;
|
||||||
running_ = false;
|
running_ = false;
|
||||||
|
E2D_INFO("应用程序模块关闭完成,准备关闭日志系统");
|
||||||
E2D_INFO("应用程序关闭完成");
|
|
||||||
|
|
||||||
// 关闭日志系统(在所有日志调用之后)
|
// 关闭日志系统(在所有日志调用之后)
|
||||||
Logger::shutdown();
|
Logger::shutdown();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -246,6 +246,10 @@ bool CommandQueue::initialize() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void CommandQueue::shutdown() {
|
void CommandQueue::shutdown() {
|
||||||
|
if (!uboManager_ && !commandList_ && !context_) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
uboManager_.reset();
|
uboManager_.reset();
|
||||||
commandList_.reset();
|
commandList_.reset();
|
||||||
context_ = nullptr;
|
context_ = nullptr;
|
||||||
|
|
|
||||||
|
|
@ -61,12 +61,14 @@ RenderGraph::RenderGraph(RenderGraph &&other) noexcept
|
||||||
builder_(std::move(other.builder_)),
|
builder_(std::move(other.builder_)),
|
||||||
commandQueue_(std::move(other.commandQueue_)),
|
commandQueue_(std::move(other.commandQueue_)),
|
||||||
outputWidth_(other.outputWidth_), outputHeight_(other.outputHeight_),
|
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.nextResourceId_ = 1;
|
||||||
other.outputWidth_ = 1280;
|
other.outputWidth_ = 1280;
|
||||||
other.outputHeight_ = 720;
|
other.outputHeight_ = 720;
|
||||||
other.frameIndex_ = 0;
|
other.frameIndex_ = 0;
|
||||||
other.compiled_ = false;
|
other.compiled_ = false;
|
||||||
|
other.initialized_ = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
RenderGraph &RenderGraph::operator=(RenderGraph &&other) noexcept {
|
RenderGraph &RenderGraph::operator=(RenderGraph &&other) noexcept {
|
||||||
|
|
@ -83,32 +85,44 @@ RenderGraph &RenderGraph::operator=(RenderGraph &&other) noexcept {
|
||||||
outputHeight_ = other.outputHeight_;
|
outputHeight_ = other.outputHeight_;
|
||||||
frameIndex_ = other.frameIndex_;
|
frameIndex_ = other.frameIndex_;
|
||||||
compiled_ = other.compiled_;
|
compiled_ = other.compiled_;
|
||||||
|
initialized_ = other.initialized_;
|
||||||
|
|
||||||
other.nextResourceId_ = 1;
|
other.nextResourceId_ = 1;
|
||||||
other.outputWidth_ = 1280;
|
other.outputWidth_ = 1280;
|
||||||
other.outputHeight_ = 720;
|
other.outputHeight_ = 720;
|
||||||
other.frameIndex_ = 0;
|
other.frameIndex_ = 0;
|
||||||
other.compiled_ = false;
|
other.compiled_ = false;
|
||||||
|
other.initialized_ = false;
|
||||||
}
|
}
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RenderGraph::initialize() {
|
bool RenderGraph::initialize() {
|
||||||
|
if (initialized_) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
if (!commandQueue_.initialize()) {
|
if (!commandQueue_.initialize()) {
|
||||||
E2D_ERROR("初始化命令队列失败");
|
E2D_ERROR("初始化命令队列失败");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
initialized_ = true;
|
||||||
E2D_INFO("渲染图已初始化");
|
E2D_INFO("渲染图已初始化");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RenderGraph::shutdown() {
|
void RenderGraph::shutdown() {
|
||||||
|
if (!initialized_) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
destroyResources();
|
destroyResources();
|
||||||
passes_.clear();
|
passes_.clear();
|
||||||
executionOrder_.clear();
|
executionOrder_.clear();
|
||||||
commandQueue_.shutdown();
|
commandQueue_.shutdown();
|
||||||
compiled_ = false;
|
compiled_ = false;
|
||||||
|
initialized_ = false;
|
||||||
|
|
||||||
E2D_INFO("渲染图已关闭");
|
E2D_INFO("渲染图已关闭");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -93,6 +93,10 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
void shutdown() override {
|
void shutdown() override {
|
||||||
|
if (!context_ && !glContext_ && !window_) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
E2D_INFO("正在关闭 OpenGL 设备...");
|
E2D_INFO("正在关闭 OpenGL 设备...");
|
||||||
|
|
||||||
if (context_) {
|
if (context_) {
|
||||||
|
|
|
||||||
|
|
@ -87,15 +87,16 @@ void RHIModule::onWindowShow() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void RHIModule::shutdown() {
|
void RHIModule::shutdown() {
|
||||||
|
if (!initialized_ && !device_ && !context_ && !onShowListener_) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
E2D_INFO("正在关闭 RHI模块...");
|
E2D_INFO("正在关闭 RHI模块...");
|
||||||
|
|
||||||
// 清理事件监听器
|
// 清理事件监听器
|
||||||
onShowListener_.reset();
|
onShowListener_.reset();
|
||||||
|
|
||||||
if (context_) {
|
|
||||||
context_->shutdown();
|
|
||||||
context_ = nullptr;
|
context_ = nullptr;
|
||||||
}
|
|
||||||
|
|
||||||
if (device_) {
|
if (device_) {
|
||||||
device_->shutdown();
|
device_->shutdown();
|
||||||
|
|
|
||||||
|
|
@ -85,6 +85,7 @@ void Logger::shutdown() {
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
initialized_ = false;
|
initialized_ = false;
|
||||||
|
log(LogLevel::Info, "日志系统关闭完成");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue