diff --git a/src/Battling/EventHooks/EventData.hpp b/src/Battling/EventHooks/EventData.hpp index 5cde29b..f23f364 100644 --- a/src/Battling/EventHooks/EventData.hpp +++ b/src/Battling/EventHooks/EventData.hpp @@ -9,6 +9,7 @@ namespace CreatureLib::Battling { class EventData { public: + virtual ~EventData() = default; virtual EventDataKind GetKind() = 0; }; diff --git a/src/Battling/EventHooks/EventHook.hpp b/src/Battling/EventHooks/EventHook.hpp index 20e0ad5..93717bc 100644 --- a/src/Battling/EventHooks/EventHook.hpp +++ b/src/Battling/EventHooks/EventHook.hpp @@ -19,6 +19,7 @@ namespace CreatureLib::Battling { for (auto listener : _listeners) { listener(eventData); } + delete eventData; } }; } diff --git a/src/Battling/Models/Battle.hpp b/src/Battling/Models/Battle.hpp index 62a7fea..baaf899 100644 --- a/src/Battling/Models/Battle.hpp +++ b/src/Battling/Models/Battle.hpp @@ -23,7 +23,7 @@ namespace CreatureLib::Battling { ChoiceQueue* _currentTurnQueue = nullptr; bool _hasEnded = false; BattleResult _battleResult = BattleResult::Empty(); - EventHook* _eventHook = new EventHook(); + EventHook _eventHook = EventHook(); ScriptSet _volatile; @@ -74,8 +74,8 @@ namespace CreatureLib::Battling { const std::vector& GetSides() const { return _sides; } - void RegisterEventListener(EVENT_HOOK_FUNC(listener)) { this->_eventHook->RegisterListener(listener); } - void TriggerEventListener(EventData* data) { this->_eventHook->TriggerEvent(data); } + void RegisterEventListener(EVENT_HOOK_FUNC(listener)) { this->_eventHook.RegisterListener(listener); } + void TriggerEventListener(EventData* data) { this->_eventHook.TriggerEvent(data); } }; }