From ff210334c4100526021e1defb6d9df0707e5bdd1 Mon Sep 17 00:00:00 2001 From: Nathan Mills <38995150+Quipyowert2@users.noreply.github.com> Date: Wed, 14 Jun 2023 16:27:49 -0700 Subject: [PATCH] Fix intermittent crash during window resizing. --- libgag/include/EventListener.h | 2 ++ libgag/src/EventListener.cpp | 7 ++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/libgag/include/EventListener.h b/libgag/include/EventListener.h index 84fe39d8..cc64018a 100644 --- a/libgag/include/EventListener.h +++ b/libgag/include/EventListener.h @@ -54,6 +54,8 @@ class EventListener { static EventListener* el; std::atomic quit, done; std::atomic depth; + + static std::mutex queueMutex; // used when pushing/popping queue. }; } #endif //__EVENTLISTENER_H \ No newline at end of file diff --git a/libgag/src/EventListener.cpp b/libgag/src/EventListener.cpp index 63c07592..17ab33dc 100644 --- a/libgag/src/EventListener.cpp +++ b/libgag/src/EventListener.cpp @@ -21,6 +21,7 @@ #include namespace GAGCore { std::deque events = std::deque(); +std::mutex EventListener::queueMutex; EventListener* EventListener::el = nullptr; std::mutex EventListener::startMutex; std::condition_variable EventListener::startedCond; @@ -180,7 +181,10 @@ void EventListener::run() sizeMoveTimerRunning = false; } #endif - events.push_back(event); + { + std::lock_guard lock(queueMutex); + events.push_back(event); + } } } { @@ -191,6 +195,7 @@ void EventListener::run() } int EventListener::poll(SDL_Event* e) { + std::lock_guard lock(queueMutex); if (events.size()) { *e = events.front(); events.pop_front();