From ae7f3783acdac648658e3a676dacd2215ab12357 Mon Sep 17 00:00:00 2001 From: French Fries God Date: Wed, 27 May 2026 11:35:50 -0400 Subject: [PATCH] Fix Memory Leak --- luth/source/luth/core/App.cpp | 1 + luth/source/luth/events/EventBus.h | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/luth/source/luth/core/App.cpp b/luth/source/luth/core/App.cpp index 540361a6..a6bc9d98 100644 --- a/luth/source/luth/core/App.cpp +++ b/luth/source/luth/core/App.cpp @@ -426,6 +426,7 @@ namespace Luth m_FrameData.Shutdown(); IOThread::Shutdown(); JobSystem::Shutdown(); + EventBus::FlushAll(); Memory::TaggedPageAllocator::Get().Shutdown(); Memory::MemoryTracker::Shutdown(); } diff --git a/luth/source/luth/events/EventBus.h b/luth/source/luth/events/EventBus.h index 7edc89b7..bd9eed95 100644 --- a/luth/source/luth/events/EventBus.h +++ b/luth/source/luth/events/EventBus.h @@ -88,6 +88,18 @@ namespace Luth GetBus(bus).ProcessEvents(); } + // Drop any queued events and subscribers without dispatching. + static void Flush(BusType bus) { + GetBus(bus).Flush(); + } + + // Drop all queued events and subscribers without dispatching. + static void FlushAll() { + for (size_t i = 0; i < static_cast(BusType::COUNT); ++i) { + GetBus(static_cast(i)).Flush(); + } + } + class BusInstance { public: template @@ -151,6 +163,20 @@ namespace Luth } } + void Flush() { + std::queue> pending; + { + std::lock_guard lock(m_QueueLock); + pending.swap(m_EventQueue); + } + + while (!pending.empty()) + pending.pop(); + + m_Subscribers.clear(); + m_NextSubId = 0; + } + template static EventTypeID GetEventTypeID() { static EventTypeID typeID = NextEventTypeID();