mirror of
https://github.com/libsdl-org/SDL.git
synced 2026-06-06 06:34:35 +00:00
(emscripten) Add null checks for gamepad in vendor/product/xinput helpers (#15313)
navigator.getGamepads() can return null for a slot if the gamepad
disconnects between the gamepadconnected event and the proxied
MAIN_THREAD_EM_ASM_INT call. This causes a TypeError when accessing
gamepad.id. Add null guards matching the pattern already used in
EMSCRIPTEN_JoystickOpen and EMSCRIPTEN_JoystickRumble.
(cherry picked from commit 59602fb473)
This commit is contained in:
parent
2798ac07ea
commit
18463ccb8f
1 changed files with 9 additions and 1 deletions
|
|
@ -37,9 +37,11 @@ static int numjoysticks = 0;
|
|||
|
||||
static int SDL_GetEmscriptenJoystickVendor(int device_index)
|
||||
{
|
||||
// Let's assume that if we're calling these function then the gamepad object definitely exists
|
||||
return MAIN_THREAD_EM_ASM_INT({
|
||||
let gamepad = navigator['getGamepads']()[$0];
|
||||
if (!gamepad) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Chrome, Edge, Opera: Wireless Controller (STANDARD GAMEPAD Vendor: 054c Product: 09cc)
|
||||
let vendor_str = 'Vendor: ';
|
||||
|
|
@ -62,6 +64,9 @@ static int SDL_GetEmscriptenJoystickProduct(int device_index)
|
|||
{
|
||||
return MAIN_THREAD_EM_ASM_INT({
|
||||
let gamepad = navigator['getGamepads']()[$0];
|
||||
if (!gamepad) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Chrome, Edge, Opera: Wireless Controller (STANDARD GAMEPAD Vendor: 054c Product: 09cc)
|
||||
let product_str = 'Product: ';
|
||||
|
|
@ -84,6 +89,9 @@ static int SDL_IsEmscriptenJoystickXInput(int device_index)
|
|||
{
|
||||
return MAIN_THREAD_EM_ASM_INT({
|
||||
let gamepad = navigator['getGamepads']()[$0];
|
||||
if (!gamepad) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Chrome, Edge, Opera: Xbox 360 Controller (XInput STANDARD GAMEPAD)
|
||||
// Firefox: xinput
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue