WebGL Error Constants

WebGL error constants (gl.INVALID_ENUM, etc.) with numeric value and cause.

Reference for the WebGL error constants returned by gl.getError(), each with its numeric value, meaning and the typical mistake that triggers it, plus a searchable lookup by name or code.

What does gl.getError() return when there is no error?

It returns gl.NO_ERROR, which equals 0. After returning any error code, the internal error flag is reset to NO_ERROR, so each error is reported only once per getError() call.

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_ERROR is 0 — always compare against gl.NO_ERROR, never a truthy check.
  • INVALID_OPERATION is a state error: usually a missing bind or incomplete object.
  • OUT_OF_MEMORY may 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_info or a debug context in development for richer messages.