BabylonJS/Babylon.js · error

Resuming WebXR depth sensing requires an active XR session.

Error message

Resuming WebXR depth sensing requires an active XR session.

What it means

resumeDepthSensingAsync resumes depth sensing on the active XR session. Like pause, it requires an active immersive session; Babylon throws this Error when inXRSession is false or the session object is missing. Resuming only makes sense within a live XRSession.

Source

Thrown at packages/dev/core/src/XR/features/WebXRDepthSensing.pure.ts:571

        if (!this._xrSessionManager.inXRSession || !session) {
            throw new Error("Pausing WebXR depth sensing requires an active XR session.");
        }
        if (typeof session.pauseDepthSensing !== "function") {
            throw new Error("XRSession.pauseDepthSensing is not supported by this XR runtime.");
        }
        return await session.pauseDepthSensing();
    }

    /**
     * Resumes depth sensing for the active XR session.
     * @returns A promise that resolves when the native resume operation completes.
     * @throws If there is no active XR session or resuming depth sensing is not supported by the runtime.
     * @see https://immersive-web.github.io/depth-sensing/
     */
    public async resumeDepthSensingAsync(): Promise<void> {
        const session: IWebXRDepthSensingSession | undefined = this._xrSessionManager.session;
        if (!this._xrSessionManager.inXRSession || !session) {
            throw new Error("Resuming WebXR depth sensing requires an active XR session.");
        }
        if (typeof session.resumeDepthSensing !== "function") {
            throw new Error("XRSession.resumeDepthSensing is not supported by this XR runtime.");
        }
        return await session.resumeDepthSensing();
    }

    /**
     * Latest cached InternalTexture which containing depth buffer information.
     * This can be used when the depth usage is "gpu".
     * @deprecated This will be removed in the future. Use latestDepthImageTexture
     */
    public get latestInternalTexture(): Nullable<InternalTexture> {
        if (!this._cachedWebGLTexture) {
            return null;
        }

        return this._getInternalTextureFromDepthInfo();

View on GitHub (pinned to 0592b347b8)

Solutions

  1. Check `xrSessionManager.inXRSession` before calling resumeDepthSensingAsync.
  2. Trigger resume from within session-lifetime events (frame loop, sessionstart) instead of external timers.
  3. Re-init depth sensing as part of session start if depth sensing is needed each session.
  4. Wrap in try/catch to absorb the race between session end and the resume call.

Example fix

// before
await depthSensing.resumeDepthSensingAsync();
// after
if (xrSessionManager.inXRSession && xrSessionManager.session) {
    await depthSensing.resumeDepthSensingAsync();
} else {
    console.warn("Cannot resume depth sensing without an active XR session");
}
Defensive patterns

Strategy: validation

Validate before calling

if (!xrSessionManager.inXRSession || !xrSessionManager.session) {
    throw new Error("Cannot resume depth sensing: no active XR session");
}

Try / catch

try {
    await depthSensing.resumeDepthSensingAsync();
} catch (e) {
    if (String((e as Error).message).startsWith("Resuming WebXR depth sensing requires")) {
    // re-init on next session start instead
    } else { throw e; }
}

Prevention

When it happens

Trigger: Calling feature.resumeDepthSensingAsync() with no active session: before entering XR, after session end, or after the runtime terminated the session asynchronously.

Common situations: A 'resume depth' button clicked after the user exited the headset; an async continuation (setTimeout/promise chain) that runs post session end; calling resume during app initialization before requestSession completes.

Related errors


AI-assisted analysis of BabylonJS/Babylon.js@0592b347b8 (2026-08-30). Data as JSON: /api/errors/e4c1704491838eb3. Report an issue: GitHub.