Skip to content

Commit

Permalink
Fix intermittent crash during window resizing.
Browse files Browse the repository at this point in the history
  • Loading branch information
Quipyowert2 committed Jun 14, 2023
1 parent 4d12c90 commit ff21033
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 2 additions & 0 deletions libgag/include/EventListener.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ class EventListener {
static EventListener* el;
std::atomic<bool> quit, done;
std::atomic<int> depth;

static std::mutex queueMutex; // used when pushing/popping queue.
};
}
#endif //__EVENTLISTENER_H
7 changes: 6 additions & 1 deletion libgag/src/EventListener.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <cassert>
namespace GAGCore {
std::deque<SDL_Event> events = std::deque<SDL_Event>();
std::mutex EventListener::queueMutex;
EventListener* EventListener::el = nullptr;
std::mutex EventListener::startMutex;
std::condition_variable EventListener::startedCond;
Expand Down Expand Up @@ -180,7 +181,10 @@ void EventListener::run()
sizeMoveTimerRunning = false;
}
#endif
events.push_back(event);
{
std::lock_guard<std::mutex> lock(queueMutex);
events.push_back(event);
}
}
}
{
Expand All @@ -191,6 +195,7 @@ void EventListener::run()
}
int EventListener::poll(SDL_Event* e)
{
std::lock_guard<std::mutex> lock(queueMutex);
if (events.size()) {
*e = events.front();
events.pop_front();
Expand Down

0 comments on commit ff21033

Please sign in to comment.