pluginsystem: fix crash when unloading plugin hyprctl commands (#12821)

This commit is contained in:
Virt 2026-01-03 22:11:05 +01:00 committed by GitHub
parent 17bc3b83db
commit 922e53c68c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 6 additions and 4 deletions

View file

@ -407,7 +407,7 @@ APICALL bool HyprlandAPI::unregisterHyprCtlCommand(HANDLE handle, SP<SHyprCtlCom
if (!PLUGIN) if (!PLUGIN)
return false; return false;
std::erase(PLUGIN->m_registeredHyprctlCommands, cmd); std::erase_if(PLUGIN->m_registeredHyprctlCommands, [&](const auto& other) { return !other || other == cmd; });
g_pHyprCtl->unregisterCommand(cmd); g_pHyprCtl->unregisterCommand(cmd);
return true; return true;

View file

@ -171,8 +171,10 @@ void CPluginSystem::unloadPlugin(const CPlugin* plugin, bool eject) {
HyprlandAPI::removeDispatcher(plugin->m_handle, d); HyprlandAPI::removeDispatcher(plugin->m_handle, d);
const auto rhc = plugin->m_registeredHyprctlCommands; const auto rhc = plugin->m_registeredHyprctlCommands;
for (auto const& c : rhc) for (auto const& c : rhc) {
HyprlandAPI::unregisterHyprCtlCommand(plugin->m_handle, c); if (const auto sp = c.lock())
HyprlandAPI::unregisterHyprCtlCommand(plugin->m_handle, sp);
}
g_pConfigManager->removePluginConfig(plugin->m_handle); g_pConfigManager->removePluginConfig(plugin->m_handle);

View file

@ -27,7 +27,7 @@ class CPlugin {
std::vector<IHyprWindowDecoration*> m_registeredDecorations; std::vector<IHyprWindowDecoration*> m_registeredDecorations;
std::vector<std::pair<std::string, WP<HOOK_CALLBACK_FN>>> m_registeredCallbacks; std::vector<std::pair<std::string, WP<HOOK_CALLBACK_FN>>> m_registeredCallbacks;
std::vector<std::string> m_registeredDispatchers; std::vector<std::string> m_registeredDispatchers;
std::vector<SP<SHyprCtlCommand>> m_registeredHyprctlCommands; std::vector<WP<SHyprCtlCommand>> m_registeredHyprctlCommands;
}; };
class CPluginSystem { class CPluginSystem {