mirror of
https://github.com/libsdl-org/SDL.git
synced 2026-05-21 04:53:03 +08:00
emscripten: Fix crash on Safari when probing gamepad rumble support
Safari's older Gamepad API exposes `vibrationActuator` with `playEffect`
and `reset` but no `effects` enumeration array. The probe added in
651136ac7 dereferences `vibrationActuator['effects']['includes']`
unconditionally, throwing `TypeError: undefined is not an object` on
every Safari client that opens a connected gamepad. Add the missing
`['effects']` null check so the probe returns false on Safari instead
of aborting.
This commit is contained in:
committed by
Sam Lantinga
parent
060b74a664
commit
db7ac820f9
@@ -506,7 +506,7 @@ static bool EMSCRIPTEN_JoystickOpen(SDL_Joystick *joystick, int device_index)
|
||||
|
||||
item->rumble_available = MAIN_THREAD_EM_ASM_INT({
|
||||
let gamepad = navigator['getGamepads']()[$0];
|
||||
return gamepad && gamepad['vibrationActuator'] && gamepad['vibrationActuator']['effects']['includes']('dual-rumble');
|
||||
return gamepad && gamepad['vibrationActuator'] && gamepad['vibrationActuator']['effects'] && gamepad['vibrationActuator']['effects']['includes']('dual-rumble');
|
||||
}, item->index);
|
||||
|
||||
if (item->rumble_available) {
|
||||
@@ -515,7 +515,7 @@ static bool EMSCRIPTEN_JoystickOpen(SDL_Joystick *joystick, int device_index)
|
||||
|
||||
item->trigger_rumble_available = MAIN_THREAD_EM_ASM_INT({
|
||||
let gamepad = navigator['getGamepads']()[$0];
|
||||
return gamepad && gamepad['vibrationActuator'] && gamepad['vibrationActuator']['effects']['includes']('trigger-rumble');
|
||||
return gamepad && gamepad['vibrationActuator'] && gamepad['vibrationActuator']['effects'] && gamepad['vibrationActuator']['effects']['includes']('trigger-rumble');
|
||||
}, item->index);
|
||||
|
||||
if (item->trigger_rumble_available) {
|
||||
|
||||
Reference in New Issue
Block a user