Skip to content

Commit

Permalink
Stability fixes
Browse files Browse the repository at this point in the history
Fixes exceptions when running via debugger
  • Loading branch information
zziger committed Aug 13, 2023
1 parent 8c288d1 commit 4cf82bf
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
18 changes: 9 additions & 9 deletions src/events/EventManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ typedef std::multimap<const std::string, TEventPair> TEventMap;

class EventManager {
static inline TEventMap _eventMap = {};
static inline std::unordered_set<std::string> _enabledEvents;
static inline std::unordered_set<std::string> _enabledEvents {};
static inline std::atomic_uint32_t _lastId = 0;
inline static std::recursive_mutex _mutex {};

Expand Down Expand Up @@ -138,9 +138,9 @@ class EventManager {

static uint32_t Off(const uint32_t id) {
std::lock_guard lock(_mutex);
for (auto iter = _eventMap.begin(); iter != _eventMap.end(); ++iter) {
if (iter->second.first == id) _eventMap.erase(iter);
}
std::erase_if(_eventMap, [&](const auto& item) {
return item.second.first == id;
});
return id;
}

Expand All @@ -161,16 +161,16 @@ class EventManager {
}
}

for (auto fn : fns) fn.second(event);
for (auto& fn : fns) fn.second(event);

for (const auto luaContext : GetLuaContexts()) luaContext->EmitEvent(typeId, event);
for (const auto& luaContext : GetLuaContexts()) luaContext->EmitEvent(typeId, event);
}

template <std::derived_from<IAnyEvent> Event>
static void Emit(Event&& event) {
const std::string typeId = Event::eventId;

std::vector<TEventPair> fns;
std::vector<TEventPair> fns{};
{
std::lock_guard lock(_mutex);
if (_enabledEvents.contains(typeId))
Expand All @@ -181,9 +181,9 @@ class EventManager {
}
}

for (auto fn : fns) fn.second(event);
for (auto& fn : fns) fn.second(event);

for (const auto luaContext : GetLuaContexts()) luaContext->EmitEvent(typeId, event);
for (const auto& luaContext : GetLuaContexts()) luaContext->EmitEvent(typeId, event);
}

struct Ready {
Expand Down
2 changes: 1 addition & 1 deletion src/modloader/mods/ModManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ void ModManager::InitMods(bool manual) {
const auto firstIt = std::filesystem::directory_iterator(_mods_folder);
for (auto& file : firstIt) {
if (!file.is_directory()) continue;
if (!exists(file.path() / "manifest.yml")) continue;
if (!exists(std::filesystem::path(file.path()) / std::string("manifest.yml"))) continue;
const auto modName = file.path().filename().generic_string();

try {
Expand Down

0 comments on commit 4cf82bf

Please sign in to comment.