File tree Expand file tree Collapse file tree 2 files changed +8
-1
lines changed
Expand file tree Collapse file tree 2 files changed +8
-1
lines changed Original file line number Diff line number Diff line change @@ -54,6 +54,8 @@ class EventListener {
5454 static EventListener* el;
5555 std::atomic<bool > quit, done;
5656 std::atomic<int > depth;
57+
58+ static std::mutex queueMutex; // used when pushing/popping queue.
5759};
5860}
5961#endif // __EVENTLISTENER_H
Original file line number Diff line number Diff line change 2121#include < cassert>
2222namespace GAGCore {
2323std::deque<SDL_Event> events = std::deque<SDL_Event>();
24+ std::mutex EventListener::queueMutex;
2425EventListener* EventListener::el = nullptr ;
2526std::mutex EventListener::startMutex;
2627std::condition_variable EventListener::startedCond;
@@ -180,7 +181,10 @@ void EventListener::run()
180181 sizeMoveTimerRunning = false ;
181182 }
182183#endif
183- events.push_back (event);
184+ {
185+ std::lock_guard<std::mutex> lock (queueMutex);
186+ events.push_back (event);
187+ }
184188 }
185189 }
186190 {
@@ -191,6 +195,7 @@ void EventListener::run()
191195}
192196int EventListener::poll (SDL_Event* e)
193197{
198+ std::lock_guard<std::mutex> lock (queueMutex);
194199 if (events.size ()) {
195200 *e = events.front ();
196201 events.pop_front ();
You can’t perform that action at this time.
0 commit comments