Skip to content

Commit

Permalink
Fix errors when buttons are pressed on Quest 2 controllers before the…
Browse files Browse the repository at this point in the history
… model is loaded (#5223)

* Check if buttonObjects or buttonMeshes is defined before accessing it, this fixes Quest 2 buttons highlighting errors when the model is not loaded yet (fix #5212 and #5220)

* check this.buttonMeshes before calling this.onButtonChangedV3

* Revert "check this.buttonMeshes before calling this.onButtonChangedV3"

This reverts commit 7b2cda9.
  • Loading branch information
vincentfretin committed Mar 30, 2023
1 parent 84e766f commit 14a882d
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/components/oculus-touch-controls.js
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,7 @@ module.exports.Component = registerComponent('oculus-touch-controls', {
var buttonObjects = this.buttonObjects;
var analogValue;

if (!buttonObjects) { return; }
analogValue = evt.detail.state.value;
analogValue *= this.data.hand === 'left' ? -1 : 1;

Expand Down Expand Up @@ -491,11 +492,13 @@ module.exports.Component = registerComponent('oculus-touch-controls', {

updateButtonModel: function (buttonName, state) {
// update the button mesh colors
var button;
var color = (state === 'up' || state === 'touchend') ? this.buttonMeshes[buttonName].originalColor || this.data.buttonColor : state === 'touchstart' ? this.data.buttonTouchColor : this.data.buttonHighlightColor;
var buttonMeshes = this.buttonMeshes;
var button;
var color;

if (buttonMeshes && buttonMeshes[buttonName]) {
if (!buttonMeshes) { return; }
if (buttonMeshes[buttonName]) {
color = (state === 'up' || state === 'touchend') ? buttonMeshes[buttonName].originalColor || this.data.buttonColor : state === 'touchstart' ? this.data.buttonTouchColor : this.data.buttonHighlightColor;
button = buttonMeshes[buttonName];
button.material.color.set(color);
this.rendererSystem.applyColorCorrection(button.material.color);
Expand Down

0 comments on commit 14a882d

Please sign in to comment.