Skip to main content
New Participant
Nov 19, 2026 1:14 AM UTC
Question

Quest Browser 157: starting a second WebGPU immersive session loses every WebGPU device in the page

**Device / browser**
- Meta Quest 3
- Quest Browser 157.0.0.22.15.1116689667 (Chrome/157.0.8103.38), default flags


**Summary**
In a page that uses the WebXR/WebGPU binding (`XRGPUBinding`), the first `immersive-vr` session renders normally. When a second immersive session starts in the same page, about 25 ms after `requestSession` resolves, every WebGPU device in the page is lost with:

> `GPUDevice.lost`: reason=`unknown`, message=`"A valid external Instance reference no longer exists."`

This includes the new device created for the second session and the first session's device, even though the first session has already ended. The second session shows nothing, or stays black. In a larger app (three.js WebGPURenderer), every later frame then throws `OperationError: Failed to execute 'getViewSubImage' on 'XRGPUBinding': Unable to acquire the WebGPU projection layer texture.` For a while afterwards, `navigator.gpu.requestAdapter()` and `canvas.getContext('webgl2')` both return `null` in that page.

The same flow on WebGL2 (`XRWebGLLayer`) works for any number of sessions.

**Steps to reproduce** (minimal page below, served from localhost or HTTPS)
1. Tap **Enter VR (WebGPU)**. The view clears to green for about 3 s and the session ends by itself.
2. Tap **Enter VR (WebGPU)** again.
3. For comparison, tap **Enter VR (WebGL2)** two or more times.

**Expected:** the second WebGPU session renders like the first one.

**Actual** (log from the page on my Quest 3):
```
#1 WebGPU session started, enabledFeatures=["local","viewer","webxr","webgpu"]
#1 WebGPU frames ok=270 failed=0
#2 WebGPU session started, enabledFeatures=["local","viewer","webxr","webgpu"]
#1 WebGPU device lost: reason=unknown message="A valid external Instance reference no longer exists."
#2 WebGPU device lost: reason=unknown message="A valid external Instance reference no longer exists."
#3 WebGL2 session started
#3 WebGL2 frames ok=270 lost=false
#4 WebGL2 session started
#4 WebGL2 frames ok=270 lost=false
```

It makes no difference whether the first session's device is destroyed or kept alive before the second session starts.

**Workaround:** use WebGL2 for XR on Quest Browser. Possibly related: playcanvas/engine#9878 reports the same `getViewSubImage` error on Quest 3 after sleep/wake.

**Repro page**
```html
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>WebGPU XR second-session repro</title>
<style>
  body { font: 16px system-ui, sans-serif; margin: 24px; background: #111; color: #eee; }
  button { font-size: 20px; padding: 12px 20px; margin: 4px 8px 4px 0; }
  pre { background: #000; padding: 12px; white-space: pre-wrap; font-size: 13px; }
</style>
</head>
<body>
<h1>WebGPU XR: second immersive session loses the device</h1>
<p>Tap <b>Enter VR (WebGPU)</b>. The view clears to green for ~3 s, then the session ends by itself.
Tap it a second time. Compare with <b>Enter VR (WebGL2)</b>, which works every time.</p>
<button id="gpu">Enter VR (WebGPU)</button>
<button id="gl">Enter VR (WebGL2)</button>
<pre id="log"></pre>
<script>
const logEl = document.getElementById("log");
const log = (...a) => { const s = `${performance.now().toFixed(0)}ms  ${a.join(" ")}`; console.log(s); logEl.textContent += s + "\n"; };
log(navigator.userAgent);
let attempt = 0;
const FRAMES = 270; // ~3 s at 90 Hz

async function runWebGPU() {
  const n = ++attempt;
  let session;
  try {
    const adapter = await navigator.gpu.requestAdapter({ xrCompatible: true });
    if (!adapter) throw new Error("requestAdapter returned null");
    const device = await adapter.requestDevice();
    device.lost.then((i) => log(`#${n} WebGPU device lost: reason=${i.reason} message="${i.message}"`));
    session = await navigator.xr.requestSession("immersive-vr", { optionalFeatures: ["webgpu"] });
    log(`#${n} WebGPU session started, enabledFeatures=${JSON.stringify(session.enabledFeatures)}`);
    const binding = new XRGPUBinding(session, device);
    const layer = binding.createProjectionLayer({ colorFormat: binding.getPreferredColorFormat() });
    session.updateRenderState({ layers: [layer] });
    const space = await session.requestReferenceSpace("local");
    let ok = 0, fail = 0, firstErr = null;
    await new Promise((resolve) => {
      let frames = 0;
      const onFrame = (t, frame) => {
        try {
          const pose = frame.getViewerPose(space);
          if (pose) {
            const enc = device.createCommandEncoder();
            for (const view of pose.views) {
              const sub = binding.getViewSubImage(layer, view);
              enc.beginRenderPass({ colorAttachments: [{ view: sub.colorTexture.createView(sub.getViewDescriptor()), loadOp: "clear", storeOp: "store", clearValue: [0, 0.5, 0, 1] }] }).end();
            }
            device.queue.submit([enc.finish()]);
            ok++;
          }
        } catch (e) { fail++; firstErr ??= `${e.name}: ${e.message}`; }
        if (++frames < FRAMES) session.requestAnimationFrame(onFrame); else resolve();
      };
      session.requestAnimationFrame(onFrame);
    });
    log(`#${n} WebGPU frames ok=${ok} failed=${fail}${firstErr ? ` firstError="${firstErr}"` : ""}`);
  } catch (e) {
    log(`#${n} WebGPU attempt failed: ${e.name}: ${e.message}`);
  }
  try { await session?.end(); } catch {}
  setTimeout(() => log(`#${n} after session: webgl2 context ${document.createElement("canvas").getContext("webgl2") ? "OK" : "NULL"}`), 500);
}

async function runWebGL() {
  const n = ++attempt;
  let session;
  try {
    const gl = document.createElement("canvas").getContext("webgl2", { xrCompatible: true });
    if (!gl) throw new Error("webgl2 context is null");
    session = await navigator.xr.requestSession("immersive-vr");
    log(`#${n} WebGL2 session started`);
    const layer = new XRWebGLLayer(session, gl);
    session.updateRenderState({ baseLayer: layer });
    const space = await session.requestReferenceSpace("local");
    let ok = 0;
    await new Promise((resolve) => {
      let frames = 0;
      const onFrame = (t, frame) => {
        if (frame.getViewerPose(space)) {
          gl.bindFramebuffer(gl.FRAMEBUFFER, layer.framebuffer);
          gl.clearColor(0, 0.5, 0, 1); gl.clear(gl.COLOR_BUFFER_BIT);
          ok++;
        }
        if (++frames < FRAMES) session.requestAnimationFrame(onFrame); else resolve();
      };
      session.requestAnimationFrame(onFrame);
    });
    log(`#${n} WebGL2 frames ok=${ok} lost=${gl.isContextLost()}`);
  } catch (e) {
    log(`#${n} WebGL2 attempt failed: ${e.name}: ${e.message}`);
  }
  try { await session?.end(); } catch {}
}

document.getElementById("gpu").onclick = runWebGPU;
document.getElementById("gl").onclick = runWebGL;
</script>
</body>
</html>
```