From e91513a5e8953cfbb69320d94e495ccf2d4d58f3 Mon Sep 17 00:00:00 2001 From: Vaxry Date: Mon, 22 Apr 2024 15:50:01 +0100 Subject: pluginapi: unregister callbacks on lost ptrs --- src/plugins/PluginAPI.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/plugins/PluginAPI.cpp') diff --git a/src/plugins/PluginAPI.cpp b/src/plugins/PluginAPI.cpp index c89918f5..4f40694c 100644 --- a/src/plugins/PluginAPI.cpp +++ b/src/plugins/PluginAPI.cpp @@ -20,7 +20,7 @@ APICALL std::shared_ptr HyprlandAPI::registerCallbackDynamic(H return nullptr; auto PFN = g_pHookSystem->hookDynamic(event, fn, handle); - PLUGIN->registeredCallbacks.emplace_back(std::make_pair<>(event, PFN)); + PLUGIN->registeredCallbacks.emplace_back(std::make_pair<>(event, std::weak_ptr(PFN))); return PFN; } @@ -31,7 +31,7 @@ APICALL bool HyprlandAPI::unregisterCallback(HANDLE handle, std::shared_ptrunhook(fn); - std::erase_if(PLUGIN->registeredCallbacks, [&](const auto& other) { return other.second == fn; }); + std::erase_if(PLUGIN->registeredCallbacks, [&](const auto& other) { return other.second.lock() == fn; }); return true; } -- cgit v1.2.3