From 1d4087e842c5f6c05fe5626c4facd6a7b15cbad0 Mon Sep 17 00:00:00 2001 From: Nathan Date: Sat, 12 Apr 2025 18:19:16 -0500 Subject: [PATCH] make ImguiModule safe to unload --- include/utils/App/App.h | 2 +- modules/ImguiModule/src/ImguiModule.cpp | 5 +++++ modules/ImguiModule/src/ImguiModule.h | 2 ++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/include/utils/App/App.h b/include/utils/App/App.h index e335854..31c9e1c 100644 --- a/include/utils/App/App.h +++ b/include/utils/App/App.h @@ -191,7 +191,7 @@ namespace Archimedes { } } - std::cout << "Successfully unloaded module: " << name << std::endl << "runOrder.empty(): " << runOrder.empty() << std::endl; + std::cout << "Successfully unloaded module: " << name << std::endl; } virtual void printHelp() = 0; diff --git a/modules/ImguiModule/src/ImguiModule.cpp b/modules/ImguiModule/src/ImguiModule.cpp index d90e5a6..8a42ba2 100644 --- a/modules/ImguiModule/src/ImguiModule.cpp +++ b/modules/ImguiModule/src/ImguiModule.cpp @@ -17,6 +17,9 @@ ImguiModule::ImguiModule(Archimedes::App* a, void* h = nullptr) : Archimedes::Mo ImguiModule::~ImguiModule() { + WindowModule* wm = (WindowModule*) moduleInstances["WindowModule"]; + wm->getRenderer()->getCmdList().erase(rcmd_it); + ImGui_ImplOpenGL3_Shutdown(); ImGui_ImplGlfw_Shutdown(); ImGui::DestroyContext(); @@ -61,6 +64,8 @@ void ImguiModule::onLoad() { ImGui::NewFrame(); }); + rcmd_it = --wm->getRenderer()->getCmdList().end()++; + //Compute first frame ahead of first WindowModule->run() ImGui_ImplOpenGL3_NewFrame(); ImGui_ImplGlfw_NewFrame(); diff --git a/modules/ImguiModule/src/ImguiModule.h b/modules/ImguiModule/src/ImguiModule.h index 7914dfb..1898b26 100644 --- a/modules/ImguiModule/src/ImguiModule.h +++ b/modules/ImguiModule/src/ImguiModule.h @@ -23,6 +23,8 @@ class ImguiModule : public Archimedes::Module { private: ImGuiContext* context; + + std::list>::iterator rcmd_it; }; #ifdef IMGUIMODULE_DYNAMIC