Decode any gl.getError() result
WebGL surfaces problems through a single error flag you read with gl.getError(),
which returns one of a small set of integer constants. This reference lists every
standard WebGL 1 and WebGL 2 error constant with its hexadecimal value, plain-English
meaning and the most common coding mistake that produces it — searchable by name or code.
How it works
WebGL keeps an internal error flag. When an API call fails, the flag is set to the
matching error enum. Calling gl.getError() returns the current flag and resets it to
gl.NO_ERROR. The constants are plain numbers shared with desktop OpenGL:
const err = gl.getError();
if (err !== gl.NO_ERROR) {
console.warn("WebGL error", err.toString(16));
}
Because the flag clears on read, call getError() immediately after the suspect
operation. Several errors can be pending; in that case the order of reporting is
implementation-defined, so fix the first one and re-check.
Tips and notes
NO_ERRORis0— always compare againstgl.NO_ERROR, never a truthy check.INVALID_OPERATIONis a state error: usually a missing bind or incomplete object.OUT_OF_MEMORYmay leave the GL object in an undefined state — recreate it.- After
CONTEXT_LOST_WEBGL, all textures, buffers and programs are invalid. - Wrap calls with
WEBGL_debug_renderer_infoor a debug context in development for richer messages.