{"record":{"id":"8dc19d21b6d0312a","repo":"BabylonJS/Babylon.js","slug":"pausing-webxr-depth-sensing-requires-an-active-xr","errorCode":null,"errorMessage":"Pausing WebXR depth sensing requires an active XR session.","messagePattern":"Pausing WebXR depth sensing requires an active XR session\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/dev/core/src/XR/features/WebXRDepthSensing.pure.ts","lineNumber":554,"sourceCode":"     * Returns false when there is no active session or the runtime does not expose the active state.\r\n     * @see https://immersive-web.github.io/depth-sensing/\r\n     * @see https://playground.babylonjs.com/#SU7NUW#0\r\n     */\r\n    public get isDepthSensingActive(): boolean {\r\n        const session: IWebXRDepthSensingSession | undefined = this._xrSessionManager.session;\r\n        return this._xrSessionManager.inXRSession && session?.depthActive === true;\r\n    }\r\n\r\n    /**\r\n     * Pauses depth sensing for the active XR session.\r\n     * @returns A promise that resolves when the native pause operation completes.\r\n     * @throws If there is no active XR session or pausing depth sensing is not supported by the runtime.\r\n     * @see https://immersive-web.github.io/depth-sensing/\r\n     */\r\n    public async pauseDepthSensingAsync(): Promise<void> {\r\n        const session: IWebXRDepthSensingSession | undefined = this._xrSessionManager.session;\r\n        if (!this._xrSessionManager.inXRSession || !session) {\r\n            throw new Error(\"Pausing WebXR depth sensing requires an active XR session.\");\r\n        }\r\n        if (typeof session.pauseDepthSensing !== \"function\") {\r\n            throw new Error(\"XRSession.pauseDepthSensing is not supported by this XR runtime.\");\r\n        }\r\n        return await session.pauseDepthSensing();\r\n    }\r\n\r\n    /**\r\n     * Resumes depth sensing for the active XR session.\r\n     * @returns A promise that resolves when the native resume operation completes.\r\n     * @throws If there is no active XR session or resuming depth sensing is not supported by the runtime.\r\n     * @see https://immersive-web.github.io/depth-sensing/\r\n     */\r\n    public async resumeDepthSensingAsync(): Promise<void> {\r\n        const session: IWebXRDepthSensingSession | undefined = this._xrSessionManager.session;\r\n        if (!this._xrSessionManager.inXRSession || !session) {\r\n            throw new Error(\"Resuming WebXR depth sensing requires an active XR session.\");\r\n        }\r","sourceCodeStart":536,"sourceCodeEnd":572,"githubUrl":"https://github.com/BabylonJS/Babylon.js/blob/0592b347b8a4ee0236089ea86a749cacfdb266d8/packages/dev/core/src/XR/features/WebXRDepthSensing.pure.ts#L536-L572","documentation":"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.","triggerScenarios":"Calling feature.pauseDepthSensingAsync() before the user entered XR (inXRSession false) or after the session ended (session undefined/null).","commonSituations":"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.","solutions":["Guard the call with `xrSessionManager.inXRSession` before invoking pauseDepthSensingAsync.","Only call pause/resume depth sensing from code paths triggered while the session is active (e.g. XR frame callbacks, session event handlers).","Listen to the session end event and clear pending pause calls.","Wrap in try/catch to handle races where the session ends between the check and the call."],"exampleFix":"// before\nawait depthSensing.pauseDepthSensingAsync();\n// after\nif (xrSessionManager.inXRSession) {\n    await depthSensing.pauseDepthSensingAsync();\n} else {\n    console.warn(\"No active XR session; skip pausing depth sensing\");\n}","handlingStrategy":"validation","validationCode":"if (!xrSessionManager.inXRSession || !xrSessionManager.session) {\n    throw new Error(\"Cannot pause depth sensing: no active XR session\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    await depthSensing.pauseDepthSensingAsync();\n} catch (e) {\n    if (String((e as Error).message).startsWith(\"Pausing WebXR depth sensing requires\")) {\n    // session gone; ignore or re-queue\n    } else { throw e; }\n}","preventionTips":["Gate pause/resume calls on xrSessionManager.inXRSession","Trigger depth-sensing controls from session-lifetime events only","Clear pending pause calls on XRSession end event","Unify depth-sensing control behind a state-aware wrapper"],"tags":["webxr","depth-sensing","session-state"],"backgroundTag":"no-active-xr-session","analyzedSha":"0592b347b8a4ee0236089ea86a749cacfdb266d8","analyzedAt":"2026-08-30T15:11:20.442Z","schemaVersion":2},"datasetVersion":"2026-08-31T09:17:48.483Z"}