diff --git a/include/helpers/plugin_handler.hpp b/include/helpers/plugin_handler.hpp index a6f41036b..128b39d02 100644 --- a/include/helpers/plugin_handler.hpp +++ b/include/helpers/plugin_handler.hpp @@ -12,6 +12,8 @@ namespace hex { class Plugin { public: Plugin(std::string_view path); + Plugin(const Plugin&) = delete; + Plugin(Plugin &&other); ~Plugin(); void initializePlugin() const; @@ -38,7 +40,7 @@ namespace hex { private: static inline std::string s_pluginFolder; - static inline std::vector s_plugins; + static inline std::vector s_plugins; }; } \ No newline at end of file diff --git a/source/helpers/plugin_handler.cpp b/source/helpers/plugin_handler.cpp index 2f244b1f9..f209eb640 100644 --- a/source/helpers/plugin_handler.cpp +++ b/source/helpers/plugin_handler.cpp @@ -8,7 +8,7 @@ namespace hex { namespace fs = std::filesystem; - // hex::plugin::internal::initializePlugin() + // hex::plugin::::internal::initializePlugin() constexpr auto InitializePluginSymbol = "_ZN3hex6plugin%d%s8internal16initializePluginEv"; Plugin::Plugin(std::string_view path) { @@ -21,6 +21,14 @@ namespace hex { this->m_initializePluginFunction = reinterpret_cast(dlsym(this->m_handle, symbolName.c_str())); } + Plugin::Plugin(Plugin &&other) { + this->m_handle = other.m_handle; + this->m_initializePluginFunction = other.m_initializePluginFunction; + + other.m_handle = nullptr; + other.m_initializePluginFunction = nullptr; + } + Plugin::~Plugin() { dlclose(this->m_handle); } @@ -39,14 +47,11 @@ namespace hex { for (auto& pluginPath : std::filesystem::directory_iterator(pluginFolder)) { if (pluginPath.is_regular_file() && pluginPath.path().extension() == ".hexplug") - PluginHandler::s_plugins.push_back(new Plugin(pluginPath.path().string())); + PluginHandler::s_plugins.emplace_back(pluginPath.path().string()); } } void PluginHandler::unload() { - for (auto &plugin : PluginHandler::s_plugins) - delete plugin; - PluginHandler::s_plugins.clear(); PluginHandler::s_pluginFolder.clear(); } diff --git a/source/window.cpp b/source/window.cpp index 075f164e5..b28141613 100644 --- a/source/window.cpp +++ b/source/window.cpp @@ -554,7 +554,7 @@ namespace hex { } catch (std::runtime_error &e) { return; } for (const auto &plugin : PluginHandler::getPlugins()) { - plugin->initializePlugin(); + plugin.initializePlugin(); } }