Skip to content
Prev Previous commit
Next Next commit
handle self.usedOfferSession state properly
  • Loading branch information
cabanier committed Dec 12, 2023
commit d1a057fe55b211050161304f5db03dab0f951528
7 changes: 5 additions & 2 deletions src/core/scene/a-scene.js
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ class AScene extends AEntity {

// Don't enter VR if already in VR.
if (useOfferSession && navigator.xr.offerSession === undefined) { return Promise.resolve('OfferSession is not supported.'); }
if (self.usedOfferSession) { return Promise.resolve('OfferSession was already called.'); }
if (self.usedOfferSession && useOfferSession) { return Promise.resolve('OfferSession was already called.'); }
if (this.is('vr-mode')) { return Promise.resolve('Already in VR.'); }

// Has VR.
Expand All @@ -302,7 +302,10 @@ class AScene extends AEntity {
requestSession(xrMode, xrInit).then(
function requestSuccess (xrSession) {
self.xrSession = xrSession;
self.usedOfferSession = false;

if (useOfferSession) {
self.usedOfferSession = false;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably can always set this to false here?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

without checking useOfferSession

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe the regular requestSession API will then also set this to false. At that point we'll be in a bad state because the offersession promise is still pending.

}

vrManager.layersEnabled = xrInit.requiredFeatures.indexOf('layers') !== -1;
vrManager.setSession(xrSession).then(function () {
Expand Down