Report a failed GPU draw instead of painting black.

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 <noreply@codebuff.com>
This commit is contained in:
2026-11-28 06:45:37 +00:00
parent 7e53bb5059
commit 32616d5404
+27
View File
@@ -2076,6 +2076,7 @@ export class Renderer {
const data = new Float32Array(w * h * 4); const data = new Float32Array(w * h * 4);
gl.readPixels(0, 0, w, h, gl.RGBA, gl.FLOAT, data); gl.readPixels(0, 0, w, h, gl.RGBA, gl.FLOAT, data);
gl.bindFramebuffer(gl.FRAMEBUFFER, null); gl.bindFramebuffer(gl.FRAMEBUFFER, null);
this.checkDrawError();
return data; return data;
} }
@@ -2103,9 +2104,35 @@ export class Renderer {
} }
} }
this.checkDrawError();
return null; 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. */ /** Wait for queued GPU work, e.g. before the canvas is encoded to a file. */
finishGpu() { finishGpu() {
this.gl.finish(); this.gl.finish();