Skip to content

Commit

Permalink
Fix reloading plugins (#835)
Browse files Browse the repository at this point in the history
Individually reload all plugins instead of dropping them all and loading them all at once
  • Loading branch information
catornot authored Jan 18, 2025
1 parent 1045478 commit f98f6b9
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 11 deletions.
12 changes: 7 additions & 5 deletions primedev/plugins/pluginmanager.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "pluginmanager.h"

#include <regex>
#include <ranges>
#include "plugins.h"
#include "config/profile.h"
#include "core/convar/concommand.h"
Expand Down Expand Up @@ -111,13 +112,14 @@ bool PluginManager::LoadPlugins(bool reloaded)

void PluginManager::ReloadPlugins()
{
for (const Plugin& plugin : this->GetLoadedPlugins())
NS::log::PLUGINSYS->info("Reloading plugins");

for (const Plugin& plugin : this->plugins | std::views::reverse)
{
plugin.Unload();
std::string name = plugin.GetName();
if (plugin.Reload())
NS::log::PLUGINSYS->info("Reloaded {}", name);
}

this->plugins.clear();
this->LoadPlugins(true);
}

void PluginManager::RemovePlugin(HMODULE handle)
Expand Down
14 changes: 9 additions & 5 deletions primedev/plugins/plugins.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,9 @@ bool Plugin::Unload() const

if (IsValid())
{
bool unloaded = m_callbacks->Unload();
bool shouldUnload = m_callbacks->Unload();

if (!unloaded)
if (!shouldUnload)
return false;
}

Expand All @@ -154,14 +154,18 @@ bool Plugin::Unload() const
return true;
}

void Plugin::Reload() const
bool Plugin::Reload() const
{
std::string location = m_location;

bool unloaded = Unload();

if (!unloaded)
return;
return false;

g_pPluginManager->LoadPlugin(fs::path(m_location), true);
g_pPluginManager->LoadPlugin(fs::path(location), true);

return true;
}

void Plugin::Log(spdlog::level::level_enum level, char* msg) const
Expand Down
2 changes: 1 addition & 1 deletion primedev/plugins/plugins.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class Plugin

Plugin(std::string path);
bool Unload() const;
void Reload() const;
bool Reload() const;

// sys
void Log(spdlog::level::level_enum level, char* msg) const;
Expand Down

0 comments on commit f98f6b9

Please sign in to comment.