Skip to content

Commit

Permalink
Fix crash caused by incorrect variable index for analog sticks
Browse files Browse the repository at this point in the history
  • Loading branch information
retro-wertz committed Jul 17, 2019
1 parent 7e88289 commit d808297
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions src/libretro/libretro.cpp
Expand Up @@ -1220,25 +1220,25 @@ static void updateInput_MotionSensors(void)
analog_y = astick_data[1];

// Gyro sensor section
analog[3] = input_cb(0, RETRO_DEVICE_ANALOG,
analog[2] = input_cb(0, RETRO_DEVICE_ANALOG,
gyro_retro_device_index, RETRO_DEVICE_ID_ANALOG_X);

if ( analog[3] < -astick_deadzone ) {
if ( analog[2] < -astick_deadzone ) {
// Re-scale analog stick range
scaled_range = (-analog[3] - astick_deadzone) *
scaled_range = (-analog[2] - astick_deadzone) *
((float)ASTICK_MAX / (ASTICK_MAX - astick_deadzone));
// Gyro sensor range is +/- 1800
scaled_range *= 1800.0 / ASTICK_MAX * (gyro_sensitivity / 100.0);
astick_data[3] = -(int16_t)ROUND(scaled_range);
} else if ( analog[3] > astick_deadzone ) {
scaled_range = (analog[3] - astick_deadzone) *
astick_data[2] = -(int16_t)ROUND(scaled_range);
} else if ( analog[2] > astick_deadzone ) {
scaled_range = (analog[2] - astick_deadzone) *
((float)ASTICK_MAX / (ASTICK_MAX - astick_deadzone));
scaled_range *= (1800.0 / ASTICK_MAX * (gyro_sensitivity / 100.0));
astick_data[3] = +(int16_t)ROUND(scaled_range);
astick_data[2] = +(int16_t)ROUND(scaled_range);
} else
astick_data[3] = 0;
astick_data[2] = 0;

analog_z = astick_data[3];
analog_z = astick_data[2];
}

// Update solar sensor level by gamepad buttons, default L2/R2
Expand Down

0 comments on commit d808297

Please sign in to comment.