mirror of https://github.com/mgba-emu/mgba.git
Fix a race condition on `InputController::m_pendingEvents`
This member could be accessed at the same from different threads leading to random (rare) crashes. Fixes #1875
This commit is contained in:
parent
e232e5ce41
commit
ca67e63abb
|
@ -384,6 +384,7 @@ int InputController::pollEvents() {
|
||||||
SDL_JoystickUpdate();
|
SDL_JoystickUpdate();
|
||||||
int numButtons = SDL_JoystickNumButtons(joystick);
|
int numButtons = SDL_JoystickNumButtons(joystick);
|
||||||
int i;
|
int i;
|
||||||
|
QReadLocker l(&m_eventsLock);
|
||||||
for (i = 0; i < numButtons; ++i) {
|
for (i = 0; i < numButtons; ++i) {
|
||||||
GBAKey key = static_cast<GBAKey>(mInputMapKey(&m_inputMap, SDL_BINDING_BUTTON, i));
|
GBAKey key = static_cast<GBAKey>(mInputMapKey(&m_inputMap, SDL_BINDING_BUTTON, i));
|
||||||
if (key == GBA_KEY_NONE) {
|
if (key == GBA_KEY_NONE) {
|
||||||
|
@ -396,6 +397,7 @@ int InputController::pollEvents() {
|
||||||
activeButtons |= 1 << key;
|
activeButtons |= 1 << key;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
l.unlock();
|
||||||
int numHats = SDL_JoystickNumHats(joystick);
|
int numHats = SDL_JoystickNumHats(joystick);
|
||||||
for (i = 0; i < numHats; ++i) {
|
for (i = 0; i < numHats; ++i) {
|
||||||
int hat = SDL_JoystickGetHat(joystick, i);
|
int hat = SDL_JoystickGetHat(joystick, i);
|
||||||
|
@ -561,6 +563,7 @@ void InputController::bindHat(uint32_t type, int hat, GamepadHatEvent::Direction
|
||||||
}
|
}
|
||||||
|
|
||||||
void InputController::testGamepad(int type) {
|
void InputController::testGamepad(int type) {
|
||||||
|
QWriteLocker l(&m_eventsLock);
|
||||||
auto activeAxes = activeGamepadAxes(type);
|
auto activeAxes = activeGamepadAxes(type);
|
||||||
auto oldAxes = m_activeAxes;
|
auto oldAxes = m_activeAxes;
|
||||||
m_activeAxes = activeAxes;
|
m_activeAxes = activeAxes;
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
|
|
||||||
#include <QImage>
|
#include <QImage>
|
||||||
#include <QMutex>
|
#include <QMutex>
|
||||||
|
#include <QReadWriteLock>
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QSet>
|
#include <QSet>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
|
@ -181,6 +182,7 @@ private:
|
||||||
QTimer m_gamepadTimer{nullptr};
|
QTimer m_gamepadTimer{nullptr};
|
||||||
|
|
||||||
QSet<GBAKey> m_pendingEvents;
|
QSet<GBAKey> m_pendingEvents;
|
||||||
|
QReadWriteLock m_eventsLock;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue