Bladeren bron

Merge pull request #7504 from RaananW/isSessionSupportedFix

Make sure isSessionSupported is taken into account
David Catuhe 5 jaren geleden
bovenliggende
commit
e3ffcb3021

+ 1 - 0
dist/preview release/what's new.md

@@ -301,6 +301,7 @@
 - Disposing of the depthReducer used in CSM ([Popov72](https://github.com/Popov72))
 - Fixed an issue with teleportation detach and attach ([#7419](https://github.com/BabylonJS/Babylon.js/issues/7419)) ([RaananW](https://github.com/RaananW/))
 - Physics compound calculations were incorrect ([#7407](https://github.com/BabylonJS/Babylon.js/issues/7407)) ([RaananW](https://github.com/RaananW/))
+- Fixed an issue with isSessionSupported return value being ignored ([#7501](https://github.com/BabylonJS/Babylon.js/issues/7501)) ([RaananW](https://github.com/RaananW/))
 
 ## Breaking changes
 

+ 4 - 1
src/Cameras/XR/webXRExperienceHelper.ts

@@ -111,7 +111,10 @@ export class WebXRExperienceHelper implements IDisposable {
             optionalFeatures: (referenceSpaceType !== "viewer" && referenceSpaceType !== "local") ? [referenceSpaceType] : []
         };
         // make sure that the session mode is supported
-        return this.sessionManager.isSessionSupportedAsync(sessionMode).then(() => {
+        return this.sessionManager.isSessionSupportedAsync(sessionMode).then((supported) => {
+            if (!supported) {
+                throw new Error(`Session mode "${sessionMode}" not supported in browser`);
+            }
             return this.sessionManager.initializeSessionAsync(sessionMode, sessionCreationOptions);
         }).then(() => {
             return this.sessionManager.setReferenceSpaceTypeAsync(referenceSpaceType);

+ 5 - 4
src/Cameras/XR/webXRSessionManager.ts

@@ -268,9 +268,9 @@ export class WebXRSessionManager implements IDisposable {
     /**
      * Checks if a session would be supported for the creation options specified
      * @param sessionMode session mode to check if supported eg. immersive-vr
-     * @returns true if supported
+     * @returns A Promise that resolves to true if supported and false if not
      */
-    public isSessionSupportedAsync(sessionMode: XRSessionMode) {
+    public isSessionSupportedAsync(sessionMode: XRSessionMode): Promise<boolean> {
         return WebXRSessionManager.IsSessionSupportedAsync(sessionMode);
     }
 
@@ -344,8 +344,9 @@ export class WebXRSessionManager implements IDisposable {
         if (!functionToUse) {
             return Promise.resolve(false);
         } else {
-            return functionToUse.call((navigator as any).xr, sessionMode).then(() => {
-                return Promise.resolve(true);
+            return functionToUse.call((navigator as any).xr, sessionMode).then((result: boolean) => {
+                const returnValue = (typeof result === "undefined") ? true : result;
+                return Promise.resolve(returnValue);
             }).catch((e: any) => {
                 Logger.Warn(e);
                 return Promise.resolve(false);