From 32616d5404b2dd2c20891a52e2308ae8f58113a9 Mon Sep 17 00:00:00 2001 From: Brian Hursey Date: Sat, 28 Nov 2026 06:45:37 +0000 Subject: [PATCH] Report a failed GPU draw instead of painting black. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A rejected draw leaves the canvas untouched, so a broken frame looked like a black photo with nothing to explain it. Poll the error queue once per frame and raise an error the editor can show. 🤖 Generated with Codebuff Co-Authored-By: Codebuff --- src/gl/renderer.ts | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/gl/renderer.ts b/src/gl/renderer.ts index a659a2f..227e2bd 100644 --- a/src/gl/renderer.ts +++ b/src/gl/renderer.ts @@ -2076,6 +2076,7 @@ export class Renderer { const data = new Float32Array(w * h * 4); gl.readPixels(0, 0, w, h, gl.RGBA, gl.FLOAT, data); gl.bindFramebuffer(gl.FRAMEBUFFER, null); + this.checkDrawError(); return data; } @@ -2103,9 +2104,35 @@ export class Renderer { } } + this.checkDrawError(); return null; } + /** + * A rejected draw leaves the canvas untouched, which the editor shows as a + * black photo with nothing to explain it. Poll the error queue once per + * frame, after the draws are queued, and let the caller report a real + * failure instead of painting black. + */ + private checkDrawError() { + const gl = this.gl; + const err = gl.getError(); + if (err === gl.NO_ERROR) return; + const name = + err === gl.INVALID_OPERATION + ? 'INVALID_OPERATION' + : err === gl.INVALID_VALUE + ? 'INVALID_VALUE' + : err === gl.INVALID_FRAMEBUFFER_OPERATION + ? 'INVALID_FRAMEBUFFER_OPERATION' + : err === gl.OUT_OF_MEMORY + ? 'OUT_OF_MEMORY' + : `0x${err.toString(16)}`; + throw new Error( + `The photo could not be drawn on this GPU (WebGL ${name}). Reload the page, and if it keeps happening update your graphics driver.`, + ); + } + /** Wait for queued GPU work, e.g. before the canvas is encoded to a file. */ finishGpu() { this.gl.finish();