{"record":{"id":"e4c1704491838eb3","repo":"BabylonJS/Babylon.js","slug":"resuming-webxr-depth-sensing-requires-an-active-xr","errorCode":null,"errorMessage":"Resuming WebXR depth sensing requires an active XR session.","messagePattern":"Resuming 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":571,"sourceCode":"        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\n        if (typeof session.resumeDepthSensing !== \"function\") {\r\n            throw new Error(\"XRSession.resumeDepthSensing is not supported by this XR runtime.\");\r\n        }\r\n        return await session.resumeDepthSensing();\r\n    }\r\n\r\n    /**\r\n     * Latest cached InternalTexture which containing depth buffer information.\r\n     * This can be used when the depth usage is \"gpu\".\r\n     * @deprecated This will be removed in the future. Use latestDepthImageTexture\r\n     */\r\n    public get latestInternalTexture(): Nullable<InternalTexture> {\r\n        if (!this._cachedWebGLTexture) {\r\n            return null;\r\n        }\r\n\r\n        return this._getInternalTextureFromDepthInfo();\r","sourceCodeStart":553,"sourceCodeEnd":589,"githubUrl":"https://github.com/BabylonJS/Babylon.js/blob/0592b347b8a4ee0236089ea86a749cacfdb266d8/packages/dev/core/src/XR/features/WebXRDepthSensing.pure.ts#L553-L589","documentation":"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.","triggerScenarios":"Calling feature.resumeDepthSensingAsync() with no active session: before entering XR, after session end, or after the runtime terminated the session asynchronously.","commonSituations":"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.","solutions":["Check `xrSessionManager.inXRSession` before calling resumeDepthSensingAsync.","Trigger resume from within session-lifetime events (frame loop, sessionstart) instead of external timers.","Re-init depth sensing as part of session start if depth sensing is needed each session.","Wrap in try/catch to absorb the race between session end and the resume call."],"exampleFix":"// before\nawait depthSensing.resumeDepthSensingAsync();\n// after\nif (xrSessionManager.inXRSession && xrSessionManager.session) {\n    await depthSensing.resumeDepthSensingAsync();\n} else {\n    console.warn(\"Cannot resume depth sensing without an active XR session\");\n}","handlingStrategy":"validation","validationCode":"if (!xrSessionManager.inXRSession || !xrSessionManager.session) {\n    throw new Error(\"Cannot resume depth sensing: no active XR session\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    await depthSensing.resumeDepthSensingAsync();\n} catch (e) {\n    if (String((e as Error).message).startsWith(\"Resuming WebXR depth sensing requires\")) {\n    // re-init on next session start instead\n    } else { throw e; }\n}","preventionTips":["Check inXRSession before resume calls","Re-enable depth sensing at session start rather than resuming across sessions","Handle session-end events to cancel queued resume operations","Centralize depth-sensing state transitions in one module"],"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-30T18:17:15.746Z"}