From 9032dda232e5d7e178b1d9e40ab37dd25973459c Mon Sep 17 00:00:00 2001 From: Loek Le Blansch Date: Fri, 20 Dec 2024 18:42:04 +0100 Subject: fix EventManager memory leak --- src/crepe/manager/EventManager.hpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'src/crepe/manager/EventManager.hpp') diff --git a/src/crepe/manager/EventManager.hpp b/src/crepe/manager/EventManager.hpp index a5f4556..b2090d0 100644 --- a/src/crepe/manager/EventManager.hpp +++ b/src/crepe/manager/EventManager.hpp @@ -22,7 +22,12 @@ void EventManager::queue_event(const EventType & event, event_channel_t channel) static_assert(std::is_base_of::value, "EventType must derive from Event"); this->events_queue.push_back(QueueEntry{ - .event = std::make_unique(event), + // unique_ptr w/ custom destructor implementation is used because the base Event interface + // can't be polymorphic (= have default virtual destructor) + .event = { + new EventType(event), + [](Event * ev) { delete static_cast(ev); }, + }, .channel = channel, .type = typeid(EventType), }); -- cgit v1.2.3