Explorar o código

[HTML5] Add checks to Gamepad API events.

In some conditions the events might be generated even when the `gamepad`
object is not accessible due to Security Context requirements.
This commit adds a check to avoid firing the handler in those cases.

(cherry picked from commit 91dbc288ccd7cab7d50feccba82ebfb99b5f2b69)
Fabio Alessandrelli %!s(int64=3) %!d(string=hai) anos
pai
achega
f56b1a5af5
Modificáronse 1 ficheiros con 6 adicións e 2 borrados
  1. 6 2
      platform/javascript/js/libs/library_godot_input.js

+ 6 - 2
platform/javascript/js/libs/library_godot_input.js

@@ -104,10 +104,14 @@ const GodotInputGamepads = {
 				}
 			}
 			GodotEventListeners.add(window, 'gamepadconnected', function (evt) {
-				add(evt.gamepad);
+				if (evt.gamepad) {
+					add(evt.gamepad);
+				}
 			}, false);
 			GodotEventListeners.add(window, 'gamepaddisconnected', function (evt) {
-				onchange(evt.gamepad.index, 0);
+				if (evt.gamepad) {
+					onchange(evt.gamepad.index, 0);
+				}
 			}, false);
 		},