Skip to content

Commit

Permalink
fix(skyrim-platform): fix crash related to bad event names (#1710)
Browse files Browse the repository at this point in the history
  • Loading branch information
Pospelove authored Sep 27, 2023
1 parent 6f2c6fe commit 9c6d1e4
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 24 deletions.
1 change: 1 addition & 0 deletions docs/release/dev/sp-fix-event-crash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed crash during hot-reload after an attempt to register a non-existent event listener.
34 changes: 34 additions & 0 deletions skyrim-platform/src/platform_se/skyrim_platform/EventManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,3 +152,37 @@ void EventManager::Unsubscribe(uintptr_t uid,
}
}
}

void EventManager::ClearCallbacks()
{
for (const auto& event : events) {
if (event.second) {
event.second->callbacks.clear();
}
}

auto handler = EventHandler::GetSingleton();
handler->DeactivateAllSinks();
}

CallbackObjMap* EventManager::GetCallbackObjMap(const char* eventName)
{
auto event = events[eventName];

if (!event) {
return nullptr;
}

return &event->callbacks;
}

void EventManager::EmplaceEvent(const std::string_view& name,
EventState* state)
{
events.emplace(name, state);
}

EventMap* EventManager::GetEventMap()
{
return &events;
}
28 changes: 4 additions & 24 deletions skyrim-platform/src/platform_se/skyrim_platform/EventManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,34 +80,14 @@ class EventManager

void Unsubscribe(uintptr_t uid, const std::string_view& eventName);

void ClearCallbacks()
{
for (const auto& event : events) {
event.second->callbacks.clear();
}

auto handler = EventHandler::GetSingleton();
handler->DeactivateAllSinks();
}

CallbackObjMap* GetCallbackObjMap(const char* eventName)
{
auto event = events[eventName];
void ClearCallbacks();

if (!event) {
return nullptr;
}

return &event->callbacks;
}
CallbackObjMap* GetCallbackObjMap(const char* eventName);

void EmplaceEvent(const std::string_view& name,
EventState* state = new EventState(nullptr))
{
events.emplace(name, state);
}
EventState* state = new EventState(nullptr));

EventMap* GetEventMap() { return &events; }
EventMap* GetEventMap();

private:
// last i checked we had ~97 events
Expand Down

0 comments on commit 9c6d1e4

Please sign in to comment.