Browse Source

Fixed accidentally deadlocking the rumble thread with combined Joy-Cons

Also added more accurate check for sensor data. At least one axis will always have acceleration because of gravity.
Sam Lantinga 2 years ago
parent
commit
483a010f0c
1 changed files with 13 additions and 4 deletions
  1. 13 4
      src/joystick/hidapi/SDL_hidapi_switch.c

+ 13 - 4
src/joystick/hidapi/SDL_hidapi_switch.c

@@ -1984,8 +1984,9 @@ static void HandleFullControllerState(SDL_Joystick *joystick, SDL_DriverSwitch_C
     }
 
     if (ctx->m_bReportSensors) {
-        SDL_bool bHasSensorData = (packet->imuState[0].sAccelX != 0 ||
-                                   packet->imuState[0].sGyroX != 0);
+        SDL_bool bHasSensorData = (packet->imuState[0].sAccelZ != 0 ||
+                                   packet->imuState[0].sAccelY != 0 ||
+                                   packet->imuState[0].sAccelX != 0);
         if (bHasSensorData) {
             ctx->m_bHasSensorData = SDL_TRUE;
 
@@ -1999,9 +2000,17 @@ static void HandleFullControllerState(SDL_Joystick *joystick, SDL_DriverSwitch_C
 
         } else if (ctx->m_bHasSensorData) {
             /* Uh oh, someone turned off the IMU? */
-            SDL_UnlockMutex(ctx->device->dev_lock);
+            SDL_HIDAPI_Device *device = ctx->device;
+
+            if (device->updating) {
+                SDL_UnlockMutex(device->dev_lock);
+            }
+
             SetIMUEnabled(ctx, SDL_TRUE);
-            SDL_LockMutex(ctx->device->dev_lock);
+
+            if (device->updating) {
+                SDL_LockMutex(device->dev_lock);
+            }
 
         } else {
             /* We have never gotten IMU data, probably not supported on this device */