diff --git a/src/Compositor.cpp b/src/Compositor.cpp index 18bdaaab..26565b18 100644 --- a/src/Compositor.cpp +++ b/src/Compositor.cpp @@ -285,6 +285,10 @@ void CCompositor::cleanup() { m_bIsShuttingDown = true; + // unload all remaining plugins while the compositor is + // still in a normal working state. + g_pPluginSystem->unloadAllPlugins(); + m_pLastFocus = nullptr; m_pLastWindow = nullptr; diff --git a/src/plugins/PluginSystem.cpp b/src/plugins/PluginSystem.cpp index 5b15782d..73de9bf5 100644 --- a/src/plugins/PluginSystem.cpp +++ b/src/plugins/PluginSystem.cpp @@ -1,6 +1,7 @@ #include "PluginSystem.hpp" #include +#include #include "../Compositor.hpp" CPluginSystem::CPluginSystem() { @@ -113,6 +114,11 @@ void CPluginSystem::unloadPlugin(const CPlugin* plugin, bool eject) { std::erase_if(m_vLoadedPlugins, [&](const auto& other) { return other->m_pHandle == plugin->m_pHandle; }); } +void CPluginSystem::unloadAllPlugins() { + for (auto& p : m_vLoadedPlugins | std::views::reverse) + unloadPlugin(p.get(), false); // Unload remaining plugins gracefully +} + CPlugin* CPluginSystem::getPluginByPath(const std::string& path) { for (auto& p : m_vLoadedPlugins) { if (p->path == path) @@ -136,4 +142,4 @@ std::vector CPluginSystem::getAllPlugins() { for (size_t i = 0; i < m_vLoadedPlugins.size(); ++i) results[i] = m_vLoadedPlugins[i].get(); return results; -} \ No newline at end of file +} diff --git a/src/plugins/PluginSystem.hpp b/src/plugins/PluginSystem.hpp index 041ee47e..5d1a1532 100644 --- a/src/plugins/PluginSystem.hpp +++ b/src/plugins/PluginSystem.hpp @@ -29,6 +29,7 @@ class CPluginSystem { CPlugin* loadPlugin(const std::string& path); void unloadPlugin(const CPlugin* plugin, bool eject = false); + void unloadAllPlugins(); CPlugin* getPluginByPath(const std::string& path); CPlugin* getPluginByHandle(HANDLE handle); std::vector getAllPlugins(); @@ -41,4 +42,4 @@ class CPluginSystem { jmp_buf m_jbPluginFaultJumpBuf; }; -inline std::unique_ptr g_pPluginSystem; \ No newline at end of file +inline std::unique_ptr g_pPluginSystem;