Fix potential race condition

This commit is contained in:
Isaac Marovitz 2024-04-05 17:43:10 -04:00
parent a8704e54b4
commit 3937b08ae7
No known key found for this signature in database
GPG key ID: 97250B2B09A132E1

View file

@ -275,18 +275,21 @@ namespace Ryujinx.Input.HLE
public void Update()
{
if (_gamepad != null && GamepadDriver != null)
// _gamepad may be altered by other threads
var gamepad = _gamepad;
if (gamepad != null && GamepadDriver != null)
{
State = _gamepad.GetMappedStateSnapshot();
State = gamepad.GetMappedStateSnapshot();
if (_config is StandardControllerInputConfig controllerConfig && controllerConfig.Motion.EnableMotion)
{
if (controllerConfig.Motion.MotionBackend == MotionInputBackendType.GamepadDriver)
{
if (_gamepad.Features.HasFlag(GamepadFeaturesFlag.Motion))
if (gamepad.Features.HasFlag(GamepadFeaturesFlag.Motion))
{
Vector3 accelerometer = _gamepad.GetMotionData(MotionInputId.Accelerometer);
Vector3 gyroscope = _gamepad.GetMotionData(MotionInputId.Gyroscope);
Vector3 accelerometer = gamepad.GetMotionData(MotionInputId.Accelerometer);
Vector3 gyroscope = gamepad.GetMotionData(MotionInputId.Gyroscope);
accelerometer = new Vector3(accelerometer.X, -accelerometer.Z, accelerometer.Y);
gyroscope = new Vector3(gyroscope.X, -gyroscope.Z, gyroscope.Y);