diff options
author | Cara Salter <cara@devcara.com> | 2023-04-03 09:39:39 -0400 |
---|---|---|
committer | Cara Salter <cara@devcara.com> | 2023-04-03 09:39:39 -0400 |
commit | 27e58363dde28f4667761970fc7068be8fe047ac (patch) | |
tree | 1150459da073130084cd6a1b27076da98679b964 /src/modules.cpp | |
parent | 53913850062506ff1d98d9d12a46a70db4d6fb08 (diff) | |
download | 142bot-27e58363dde28f4667761970fc7068be8fe047ac.tar.gz 142bot-27e58363dde28f4667761970fc7068be8fe047ac.zip |
modules: Fix issue with unloading modules bound to OnMessage
When unloaded, modules attached to OnMessage events would still be part
of the list used by FOREACH_MOD to send events to, leading to a
segfault.
This changes the behavior of load and unload to place new modules at the
*start* of the event handler arrays, leading them to already be
processed by the time the bot gets to the ModuleManager.
Diffstat (limited to 'src/modules.cpp')
-rw-r--r-- | src/modules.cpp | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/src/modules.cpp b/src/modules.cpp index b2e56e1..0c9fb18 100644 --- a/src/modules.cpp +++ b/src/modules.cpp @@ -57,7 +57,7 @@ ModuleLoader::ModuleLoader(Bot* creator): bot(creator) { void ModuleLoader::attach(const std::vector<Events> &i, Module* m) { for (auto n = i.begin(); n != i.end(); ++n) { if (std::find(EventHandlers[*n].begin(), EventHandlers[*n].end(), m) == EventHandlers[*n].end()) { - EventHandlers[*n].push_back(m); + EventHandlers[*n].insert(EventHandlers[*n].begin(), m); bot->core->log(dpp::ll_info, fmt::format("Module {} attached to event {}", m->description(), StringNames[*n])); } else { bot->core->log(dpp::ll_warning, fmt::format("Module {} already attached to event {}", m->description(), StringNames[*n])); |