From 19edbe989a62bb1be728f56faa881432b9a63028 Mon Sep 17 00:00:00 2001 From: Artem Bolgar Date: Tue, 22 Jan 2019 12:58:03 -0800 Subject: [PATCH] Fixing an unhandled exception that may occur when the number of the expected buttons/axes is greater than the actual buttons / axes reported by the browser. --- VRController.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/VRController.js b/VRController.js index 0811c71..9c0c0ed 100644 --- a/VRController.js +++ b/VRController.js @@ -170,16 +170,22 @@ THREE.VRController = function( gamepad ){ this.style = supported.style if( supported.axes !== undefined ){ - supported.axes.forEach( function( axesMap ){ + supported.axes.forEach( function( axesMap, i ){ - axes.byName[ axesMap.name ] = axesMap.indexes + if ( i < axes.length ){ + + axes.byName[ axesMap.name ] = axesMap.indexes + } }) } if( supported.buttons !== undefined ){ supported.buttons.forEach( function( buttonName, i ){ - buttons[ i ].name = buttonName + if ( i < buttons.length ){ + + buttons[ i ].name = buttonName + } }) } buttonNamePrimary = supported.primary