From 922e53c68c32a030c410781829e5e3acab5d7762 Mon Sep 17 00:00:00 2001 From: Virt <41426325+VirtCode@users.noreply.github.com> Date: Sat, 3 Jan 2026 22:11:05 +0100 Subject: [PATCH] pluginsystem: fix crash when unloading plugin hyprctl commands (#12821) --- src/plugins/PluginAPI.cpp | 2 +- src/plugins/PluginSystem.cpp | 6 ++++-- src/plugins/PluginSystem.hpp | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/plugins/PluginAPI.cpp b/src/plugins/PluginAPI.cpp index 1d6586aa..2abddc90 100644 --- a/src/plugins/PluginAPI.cpp +++ b/src/plugins/PluginAPI.cpp @@ -407,7 +407,7 @@ APICALL bool HyprlandAPI::unregisterHyprCtlCommand(HANDLE handle, SPm_registeredHyprctlCommands, cmd); + std::erase_if(PLUGIN->m_registeredHyprctlCommands, [&](const auto& other) { return !other || other == cmd; }); g_pHyprCtl->unregisterCommand(cmd); return true; diff --git a/src/plugins/PluginSystem.cpp b/src/plugins/PluginSystem.cpp index 53b05bc8..0549c81b 100644 --- a/src/plugins/PluginSystem.cpp +++ b/src/plugins/PluginSystem.cpp @@ -171,8 +171,10 @@ void CPluginSystem::unloadPlugin(const CPlugin* plugin, bool eject) { HyprlandAPI::removeDispatcher(plugin->m_handle, d); const auto rhc = plugin->m_registeredHyprctlCommands; - for (auto const& c : rhc) - HyprlandAPI::unregisterHyprCtlCommand(plugin->m_handle, c); + for (auto const& c : rhc) { + if (const auto sp = c.lock()) + HyprlandAPI::unregisterHyprCtlCommand(plugin->m_handle, sp); + } g_pConfigManager->removePluginConfig(plugin->m_handle); diff --git a/src/plugins/PluginSystem.hpp b/src/plugins/PluginSystem.hpp index ed421960..286f10d5 100644 --- a/src/plugins/PluginSystem.hpp +++ b/src/plugins/PluginSystem.hpp @@ -27,7 +27,7 @@ class CPlugin { std::vector m_registeredDecorations; std::vector>> m_registeredCallbacks; std::vector m_registeredDispatchers; - std::vector> m_registeredHyprctlCommands; + std::vector> m_registeredHyprctlCommands; }; class CPluginSystem {