Resolve memory issue with Event Hooks.
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Deukhoofd 2019-12-15 12:27:56 +01:00
parent 410487c86b
commit db002c784f
Signed by: Deukhoofd
GPG Key ID: ADF2E9256009EDCE
3 changed files with 5 additions and 3 deletions

View File

@ -9,6 +9,7 @@ namespace CreatureLib::Battling {
class EventData { class EventData {
public: public:
virtual ~EventData() = default;
virtual EventDataKind GetKind() = 0; virtual EventDataKind GetKind() = 0;
}; };

View File

@ -19,6 +19,7 @@ namespace CreatureLib::Battling {
for (auto listener : _listeners) { for (auto listener : _listeners) {
listener(eventData); listener(eventData);
} }
delete eventData;
} }
}; };
} }

View File

@ -23,7 +23,7 @@ namespace CreatureLib::Battling {
ChoiceQueue* _currentTurnQueue = nullptr; ChoiceQueue* _currentTurnQueue = nullptr;
bool _hasEnded = false; bool _hasEnded = false;
BattleResult _battleResult = BattleResult::Empty(); BattleResult _battleResult = BattleResult::Empty();
EventHook* _eventHook = new EventHook(); EventHook _eventHook = EventHook();
ScriptSet _volatile; ScriptSet _volatile;
@ -74,8 +74,8 @@ namespace CreatureLib::Battling {
const std::vector<BattleSide*>& GetSides() const { return _sides; } const std::vector<BattleSide*>& GetSides() const { return _sides; }
void RegisterEventListener(EVENT_HOOK_FUNC(listener)) { this->_eventHook->RegisterListener(listener); } void RegisterEventListener(EVENT_HOOK_FUNC(listener)) { this->_eventHook.RegisterListener(listener); }
void TriggerEventListener(EventData* data) { this->_eventHook->TriggerEvent(data); } void TriggerEventListener(EventData* data) { this->_eventHook.TriggerEvent(data); }
}; };
} }