{"record":{"id":"017adbc25639e3c2","repo":"BabylonJS/Babylon.js","slug":"expected-a-webgl-graphics-binding-for-webxr-depth","errorCode":null,"errorMessage":"Expected a WebGL graphics binding for WebXR Depth Sensing.","messagePattern":"Expected a WebGL graphics binding for WebXR Depth Sensing\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/dev/core/src/XR/features/WebXRDepthSensing.pure.ts","lineNumber":692,"sourceCode":"                return false;\r\n            }\r\n            this._disableAutoAttachBeforeWebGPUGPUDepth = this._autoAttachPolicyBeforeAttach ?? this.disableAutoAttach;\r\n            this._disabledForWebGPUGPUDepth = true;\r\n            return this._disableAutoAttach(WebGPUGPUDepthWarning);\r\n        }\r\n\r\n        if (depthUsage == null || depthDataFormat == null) {\r\n            return false;\r\n        }\r\n\r\n        if (!super.attach(force)) {\r\n            return false;\r\n        }\r\n\r\n        if (!engine.isWebGPU) {\r\n            const graphicsBinding = this._xrSessionManager._getGraphicsBinding();\r\n            if (graphicsBinding.bindingType !== WebXRGraphicsBindingType.WebGL) {\r\n                throw new Error(\"Expected a WebGL graphics binding for WebXR Depth Sensing.\");\r\n            }\r\n            this._glBinding = graphicsBinding.binding;\r\n        }\r\n\r\n        IsPluginEnabled = !this.options.disableDepthSensingOnMaterials;\r\n        if (IsPluginEnabled) {\r\n            for (const plugin of ManagedMaterialPlugins) {\r\n                plugin.isEnabled = true;\r\n            }\r\n            this._onCameraObserver = this._xrSessionManager.scene.onBeforeCameraRenderObservable.add((camera) => {\r\n                if (!IsPluginEnabled) {\r\n                    return;\r\n                }\r\n                // make sure this is a webxr camera\r\n                if (camera.outputRenderTarget) {\r\n                    const viewport = camera.rigCameras.length > 0 ? camera.rigCameras[0].viewport : camera.viewport;\r\n                    ScreenSize.width = camera.outputRenderTarget.getRenderWidth() / (!engine.isWebGPU && camera.rigParent ? camera.rigParent.rigCameras.length || 1 : 1);\r\n                    ScreenSize.height = camera.outputRenderTarget.getRenderHeight();\r","sourceCodeStart":674,"sourceCodeEnd":710,"githubUrl":"https://github.com/BabylonJS/Babylon.js/blob/0592b347b8a4ee0236089ea86a749cacfdb266d8/packages/dev/core/src/XR/features/WebXRDepthSensing.pure.ts#L674-L710","documentation":"attach() for depth sensing retrieves the XR graphics binding from the session manager. Depth sensing with a WebGL-backed WebXR session requires a WebGL graphics binding; if the returned binding's bindingType is not WebGL, Babylon throws this Error. This typically means the session was created with a WebGPU graphics binding, which this path does not support.","triggerScenarios":"Attaching the WebXRDepthSensing feature when engine is not WebGPU (isWebGPU false) but the session's graphics binding reports bindingType !== WebXRGraphicsBindingType.WebGL — i.e. a non-WebGL (e.g. WebGPU) binding mismatch, or a custom/unknown binding.","commonSituations":"Mixed setups where the renderer is WebGL but the XR session manager was configured for WebGPU (or vice versa), custom _getGraphicsBinding overrides returning unexpected binding types, or plugin code expecting WebGL binding only.","solutions":["Ensure the WebXR session is created with a WebGL graphics binding when using depth sensing with a WebGL engine (align engine and session binding types).","If using WebGPU, make sure engine.isWebGPU is true so the WebGL-binding check is skipped and the WebGPU path is taken.","Inspect _xrSessionManager._getGraphicsBinding() before attach to verify bindingType === WebXRGraphicsBindingType.WebGL.","Avoid custom graphics-binding overrides that return non-WebGL bindings with a WebGL engine."],"exampleFix":"// before\nconst features = xrSessionManager.enableFeature(WebXRDepthSensing.Name);\n// after\nconst binding = xrSessionManager._getGraphicsBinding();\nif (!engine.isWebGPU && binding.bindingType !== WebXRGraphicsBindingType.WebGL) {\n    throw new Error(\"Depth sensing requires a WebGL graphics binding with a WebGL engine\");\n}\nconst features = xrSessionManager.enableFeature(WebXRDepthSensing.Name);","handlingStrategy":"validation","validationCode":"const binding = xrSessionManager._getGraphicsBinding();\nif (!engine.isWebGPU && binding.bindingType !== WebXRGraphicsBindingType.WebGL) {\n    throw new Error(\"Depth sensing requires a WebGL graphics binding with a WebGL engine\");\n}","typeGuard":"function isWebGLBinding(b: { bindingType: WebXRGraphicsBindingType; binding: unknown }): b is { bindingType: typeof WebXRGraphicsBindingType.WebGL; binding: XRWebGLBinding } {\n    return b.bindingType === WebXRGraphicsBindingType.WebGL;\n}","tryCatchPattern":"try {\n    feature.attach();\n} catch (e) {\n    if (String((e as Error).message).includes(\"Expected a WebGL graphics binding\")) {\n    console.error(\"Engine/session binding mismatch; re-create session with matching binding\");\n    } else { throw e; }\n}","preventionTips":["Keep engine type and XR session graphics binding consistent (WebGL engine -> WebGL binding)","Verify bindingType before attaching depth-sensing-dependent features","Avoid custom _getGraphicsBinding overrides unless types are guaranteed","Test both WebGPU and WebGL paths when supporting multiple backends"],"tags":["webxr","depth-sensing","webgl","graphics-binding"],"backgroundTag":"graphics-binding-mismatch","analyzedSha":"0592b347b8a4ee0236089ea86a749cacfdb266d8","analyzedAt":"2026-08-30T15:11:20.442Z","schemaVersion":2},"datasetVersion":"2026-08-30T18:17:15.746Z"}