remotion-dev/remotion · critical · Error

Failed to create WebGL program

Error message

Failed to create WebGL program

What it means

Thrown by linkProgram (packages/effects/src/noise.ts:169) when gl.createProgram() returns null before attaching the noise shaders. As with other null GL-object returns, it signals a lost WebGL2 context or an exhausted program-object budget, not a problem with the shaders themselves.

Source

Thrown at packages/effects/src/noise.ts:169

	gl.shaderSource(shader, source);
	gl.compileShader(shader);
	if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {
		const log = gl.getShaderInfoLog(shader);
		gl.deleteShader(shader);
		throw new Error(`Noise shader compile failed: ${log ?? '(no log)'}`);
	}

	return shader;
};

const linkProgram = (
	gl: WebGL2RenderingContext,
	vs: WebGLShader,
	fs: WebGLShader,
): WebGLProgram => {
	const program = gl.createProgram();
	if (!program) {
		throw new Error('Failed to create WebGL program');
	}

	gl.attachShader(program, vs);
	gl.attachShader(program, fs);
	gl.linkProgram(program);
	if (!gl.getProgramParameter(program, gl.LINK_STATUS)) {
		const log = gl.getProgramInfoLog(program);
		gl.deleteProgram(program);
		throw new Error(`Noise program link failed: ${log ?? '(no log)'}`);
	}

	return program;
};

const setupNoise = (target: HTMLCanvasElement): NoiseState => {
	const gl = target.getContext('webgl2', {
		premultipliedAlpha: true,
		alpha: true,

View on GitHub (pinned to 78fe4bb3fd)

Solutions

  1. Ensure cleanup runs (gl.deleteProgram) between effect usages and cap concurrent WebGL2 effects.
  2. Render with a healthy GPU context (GPU-enabled headless Chrome) and handle context-loss events.
  3. Probe gl.isContextLost() before setup and skip/retry the effect when true.

Example fix

// before
const program = linkProgram(gl, vs, fs); // createProgram() returned null

// after
if (gl.isContextLost()) {
  throw new Error('Cannot link noise program: WebGL2 context lost');
}
Defensive patterns

Strategy: try-catch

Validate before calling

function canCreateNoiseProgram(): boolean {
  try {
    const c = document.createElement('canvas');
    const gl = c.getContext('webgl2');
    if (!gl || gl.isContextLost()) return false;
    const p = gl.createProgram();
    const ok = !!p;
    if (p) gl.deleteProgram(p);
    return ok;
  } catch {
    return false;
  }
}

Try / catch

try {
  scene.push(noise({amount: 0.2}));
} catch (err) {
  if (/Failed to create WebGL program/.test(String(err?.message))) {
    // program budget exhausted or context lost: reduce effects and retry
  } else throw err;
}

Prevention

When it happens

Trigger: setupNoise calling linkProgram after the context was lost or after too many program objects were allocated without cleanup; compiling shaders into a context that is already dead.

Common situations: Render farms running many noise/WebGL2 effects without disposing programs; context loss during a batch render; GPU memory pressure.

Related errors


AI-assisted analysis of remotion-dev/remotion@78fe4bb3fd (2026-08-12). Data as JSON: /api/errors/2a029e449d5a3c19. Report an issue: GitHub.