BabylonJS/Babylon.js · error

Pausing WebXR depth sensing requires an active XR session.

Error message

Pausing WebXR depth sensing requires an active XR session.

What it means

pauseDepthSensingAsync pauses depth sensing on the active XR session. Babylon validates that the WebXRSessionManager is actually inside an immersive session and that a session object exists; otherwise it throws this Error. Depth sensing only exists during a live XRSession, so pausing it without one is meaningless.

Source

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

     * Returns false when there is no active session or the runtime does not expose the active state.
     * @see https://immersive-web.github.io/depth-sensing/
     * @see https://playground.babylonjs.com/#SU7NUW#0
     */
    public get isDepthSensingActive(): boolean {
        const session: IWebXRDepthSensingSession | undefined = this._xrSessionManager.session;
        return this._xrSessionManager.inXRSession && session?.depthActive === true;
    }

    /**
     * Pauses depth sensing for the active XR session.
     * @returns A promise that resolves when the native pause operation completes.
     * @throws If there is no active XR session or pausing depth sensing is not supported by the runtime.
     * @see https://immersive-web.github.io/depth-sensing/
     */
    public async pauseDepthSensingAsync(): Promise<void> {
        const session: IWebXRDepthSensingSession | undefined = this._xrSessionManager.session;
        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.");
        }

View on GitHub (pinned to 0592b347b8)

Solutions

  1. Guard the call with `xrSessionManager.inXRSession` before invoking pauseDepthSensingAsync.
  2. Only call pause/resume depth sensing from code paths triggered while the session is active (e.g. XR frame callbacks, session event handlers).
  3. Listen to the session end event and clear pending pause calls.
  4. Wrap in try/catch to handle races where the session ends between the check and the call.

Example fix

// before
await depthSensing.pauseDepthSensingAsync();
// after
if (xrSessionManager.inXRSession) {
    await depthSensing.pauseDepthSensingAsync();
} else {
    console.warn("No active XR session; skip pausing depth sensing");
}
Defensive patterns

Strategy: validation

Validate before calling

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

Try / catch

try {
    await depthSensing.pauseDepthSensingAsync();
} catch (e) {
    if (String((e as Error).message).startsWith("Pausing WebXR depth sensing requires")) {
    // session gone; ignore or re-queue
    } else { throw e; }
}

Prevention

When it happens

Trigger: Calling feature.pauseDepthSensingAsync() before the user entered XR (inXRSession false) or after the session ended (session undefined/null).

Common situations: Invoking pause from a 2D UI event that fires after session end; calling during page setup before requestSession resolves; session ended unexpectedly (user took off headset) while an app-level 'pause depth' action was queued.

Related errors


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