Fixed crash if WGI isn't correlated in RAWINPUT_JoystickRumble()
This commit is contained in:
@@ -158,6 +158,7 @@ struct joystick_hwdata
|
|||||||
Uint8 wgi_correlation_count;
|
Uint8 wgi_correlation_count;
|
||||||
Uint8 wgi_uncorrelate_count;
|
Uint8 wgi_uncorrelate_count;
|
||||||
WindowsGamingInputGamepadState *wgi_slot;
|
WindowsGamingInputGamepadState *wgi_slot;
|
||||||
|
struct __x_ABI_CWindows_CGaming_CInput_CGamepadVibration vibration;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
bool triggers_rumbling;
|
bool triggers_rumbling;
|
||||||
@@ -449,7 +450,6 @@ typedef struct WindowsGamingInputGamepadState
|
|||||||
bool used; // Is currently mapped to an SDL device
|
bool used; // Is currently mapped to an SDL device
|
||||||
bool connected; // Just used during update to track disconnected
|
bool connected; // Just used during update to track disconnected
|
||||||
Uint8 correlation_id;
|
Uint8 correlation_id;
|
||||||
struct __x_ABI_CWindows_CGaming_CInput_CGamepadVibration vibration;
|
|
||||||
} WindowsGamingInputGamepadState;
|
} WindowsGamingInputGamepadState;
|
||||||
|
|
||||||
static struct
|
static struct
|
||||||
@@ -1482,12 +1482,11 @@ static bool RAWINPUT_JoystickRumble(SDL_Joystick *joystick, Uint16 low_frequency
|
|||||||
|
|
||||||
#ifdef SDL_JOYSTICK_RAWINPUT_WGI
|
#ifdef SDL_JOYSTICK_RAWINPUT_WGI
|
||||||
// Save off the motor state in case trigger rumble is started
|
// Save off the motor state in case trigger rumble is started
|
||||||
WindowsGamingInputGamepadState *gamepad_state = ctx->wgi_slot;
|
ctx->vibration.LeftMotor = (DOUBLE)low_frequency_rumble / SDL_MAX_UINT16;
|
||||||
HRESULT hr;
|
ctx->vibration.RightMotor = (DOUBLE)high_frequency_rumble / SDL_MAX_UINT16;
|
||||||
gamepad_state->vibration.LeftMotor = (DOUBLE)low_frequency_rumble / SDL_MAX_UINT16;
|
|
||||||
gamepad_state->vibration.RightMotor = (DOUBLE)high_frequency_rumble / SDL_MAX_UINT16;
|
|
||||||
if (!rumbled && ctx->wgi_correlated) {
|
if (!rumbled && ctx->wgi_correlated) {
|
||||||
hr = __x_ABI_CWindows_CGaming_CInput_CIGamepad_put_Vibration(gamepad_state->gamepad, gamepad_state->vibration);
|
WindowsGamingInputGamepadState *gamepad_state = ctx->wgi_slot;
|
||||||
|
HRESULT hr = __x_ABI_CWindows_CGaming_CInput_CIGamepad_put_Vibration(gamepad_state->gamepad, ctx->vibration);
|
||||||
if (SUCCEEDED(hr)) {
|
if (SUCCEEDED(hr)) {
|
||||||
rumbled = true;
|
rumbled = true;
|
||||||
}
|
}
|
||||||
@@ -1509,12 +1508,11 @@ static bool RAWINPUT_JoystickRumbleTriggers(SDL_Joystick *joystick, Uint16 left_
|
|||||||
#ifdef SDL_JOYSTICK_RAWINPUT_WGI
|
#ifdef SDL_JOYSTICK_RAWINPUT_WGI
|
||||||
RAWINPUT_DeviceContext *ctx = joystick->hwdata;
|
RAWINPUT_DeviceContext *ctx = joystick->hwdata;
|
||||||
|
|
||||||
|
ctx->vibration.LeftTrigger = (DOUBLE)left_rumble / SDL_MAX_UINT16;
|
||||||
|
ctx->vibration.RightTrigger = (DOUBLE)right_rumble / SDL_MAX_UINT16;
|
||||||
if (ctx->wgi_correlated) {
|
if (ctx->wgi_correlated) {
|
||||||
WindowsGamingInputGamepadState *gamepad_state = ctx->wgi_slot;
|
WindowsGamingInputGamepadState *gamepad_state = ctx->wgi_slot;
|
||||||
HRESULT hr;
|
HRESULT hr = __x_ABI_CWindows_CGaming_CInput_CIGamepad_put_Vibration(gamepad_state->gamepad, ctx->vibration);
|
||||||
gamepad_state->vibration.LeftTrigger = (DOUBLE)left_rumble / SDL_MAX_UINT16;
|
|
||||||
gamepad_state->vibration.RightTrigger = (DOUBLE)right_rumble / SDL_MAX_UINT16;
|
|
||||||
hr = __x_ABI_CWindows_CGaming_CInput_CIGamepad_put_Vibration(gamepad_state->gamepad, gamepad_state->vibration);
|
|
||||||
if (!SUCCEEDED(hr)) {
|
if (!SUCCEEDED(hr)) {
|
||||||
return SDL_SetError("Setting vibration failed: 0x%lx", hr);
|
return SDL_SetError("Setting vibration failed: 0x%lx", hr);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user