@@ -2144,24 +2144,38 @@ var LibraryHTML5 = {
2144
2144
return JSEvents . registerOrRemoveHandler ( eventHandler ) ;
2145
2145
} ,
2146
2146
2147
+ $disableGamepadApiIfItThrows__docs : '/** @suppress {checkTypes} */' ,
2148
+ $disableGamepadApiIfItThrows : ( ) = > {
2149
+ try {
2150
+ navigator . getGamepads ( ) ;
2151
+ } catch ( e ) {
2152
+ #if ASSERTIONS
2153
+ err ( `navigator.getGamepads() exists, but failed to execute with exception ${ e } . Disabling Gamepad access.` ) ;
2154
+ #endif
2155
+ navigator . getGamepads = null ; // Disable getGamepads() so that other functions will not attempt to use it.
2156
+ return 1 ;
2157
+ }
2158
+ } ,
2159
+
2147
2160
emscripten_set_gamepadconnected_callback_on_thread__proxy : 'sync' ,
2148
- emscripten_set_gamepadconnected_callback_on_thread__deps : [ '$registerGamepadEventCallback' ] ,
2161
+ emscripten_set_gamepadconnected_callback_on_thread__deps : [ '$registerGamepadEventCallback' , '$disableGamepadApiIfItThrows' ] ,
2149
2162
emscripten_set_gamepadconnected_callback_on_thread : ( userData , useCapture , callbackfunc , targetThread ) => {
2150
- if ( ! navigator . getGamepads && ! navigator . webkitGetGamepads ) return { { { cDefs . EMSCRIPTEN_RESULT_NOT_SUPPORTED } } } ;
2163
+ if ( ! navigator . getGamepads || disableGamepadApiIfItThrows ( ) ) return { { { cDefs . EMSCRIPTEN_RESULT_NOT_SUPPORTED } } } ;
2151
2164
return registerGamepadEventCallback ( { { { cDefs . EMSCRIPTEN_EVENT_TARGET_WINDOW } } } , userData , useCapture, callbackfunc, { { { cDefs . EMSCRIPTEN_EVENT_GAMEPADCONNECTED } } } , "gamepadconnected" , targetThread) ;
2152
2165
} ,
2153
2166
2154
2167
emscripten_set_gamepaddisconnected_callback_on_thread__proxy : 'sync' ,
2155
- emscripten_set_gamepaddisconnected_callback_on_thread__deps : [ '$registerGamepadEventCallback' ] ,
2168
+ emscripten_set_gamepaddisconnected_callback_on_thread__deps : [ '$registerGamepadEventCallback' , '$disableGamepadApiIfItThrows' ] ,
2156
2169
emscripten_set_gamepaddisconnected_callback_on_thread : ( userData , useCapture , callbackfunc , targetThread ) => {
2157
- if ( ! navigator . getGamepads && ! navigator . webkitGetGamepads ) return { { { cDefs . EMSCRIPTEN_RESULT_NOT_SUPPORTED } } } ;
2170
+ if ( ! navigator . getGamepads || disableGamepadApiIfItThrows ( ) ) return { { { cDefs . EMSCRIPTEN_RESULT_NOT_SUPPORTED } } } ;
2158
2171
return registerGamepadEventCallback ( { { { cDefs . EMSCRIPTEN_EVENT_TARGET_WINDOW } } } , userData , useCapture, callbackfunc, { { { cDefs . EMSCRIPTEN_EVENT_GAMEPADDISCONNECTED } } } , "gamepaddisconnected" , targetThread) ;
2159
2172
} ,
2160
2173
2161
2174
emscripten_sample_gamepad_data__proxy : 'sync' ,
2162
- emscripten_sample_gamepad_data__deps : [ '$JSEvents' ] ,
2175
+ emscripten_sample_gamepad_data__deps : [ '$JSEvents' , '$disableGamepadApiIfItThrows' ] ,
2163
2176
emscripten_sample_gamepad_data : ( ) => {
2164
- return ( JSEvents . lastGamepadState = ( navigator . getGamepads ? navigator . getGamepads ( ) : ( navigator . webkitGetGamepads ? navigator . webkitGetGamepads ( ) : null ) ) )
2177
+ if ( ! navigator . getGamepads || disableGamepadApiIfItThrows ( ) ) return { { { cDefs . EMSCRIPTEN_RESULT_NOT_SUPPORTED } } } ;
2178
+ return ( JSEvents . lastGamepadState = navigator . getGamepads ( ) )
2165
2179
? { { { cDefs . EMSCRIPTEN_RESULT_SUCCESS } } } : { { { cDefs . EMSCRIPTEN_RESULT_NOT_SUPPORTED } } } ;
2166
2180
} ,
2167
2181
@@ -2182,7 +2196,6 @@ var LibraryHTML5 = {
2182
2196
#if ASSERTIONS
2183
2197
if ( ! JSEvents . lastGamepadState ) throw 'emscripten_get_gamepad_status() can only be called after having first called emscripten_sample_gamepad_data() and that function has returned EMSCRIPTEN_RESULT_SUCCESS!' ;
2184
2198
#endif
2185
-
2186
2199
// INVALID_PARAM is returned on a Gamepad index that never was there.
2187
2200
if ( index < 0 || index >= JSEvents . lastGamepadState . length ) return { { { cDefs . EMSCRIPTEN_RESULT_INVALID_PARAM } } } ;
2188
2201
0 commit comments