remotion-dev/remotion · critical · Error

Failed to create WebGL program

Error message

Failed to create WebGL program

What it means

Thrown from lightTrail setup when `gl.createProgram()` returns `null`. Like other GL object allocations, this only fails under context loss, OUT_OF_MEMORY, or handle exhaustion — both attached shaders compiled successfully by this point.

Source

Thrown at packages/effects/src/light-trail/light-trail-runtime.ts:57

	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(`Light trail 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(`Light trail program link failed: ${log ?? '(no log)'}`);
	}

	return program;
};

const createProgram = (
	gl: WebGL2RenderingContext,
	vertexSource: string,
	fragmentSource: string,

View on GitHub (pinned to 78fe4bb3fd)

Solutions

  1. Reuse the cached setup keyed by params instead of calling setup per frame.
  2. Listen for `webglcontextlost` and recreate state on restore.
  3. Tear down (`cleanupLightTrail`) unused effect states before allocating new ones.
  4. Ensure render workers have sufficient GPU memory; reduce concurrent compositions per worker.
Defensive patterns

Strategy: fallback

Validate before calling

const contextHealthy = (gl: WebGL2RenderingContext | null): boolean =>
  !!gl && !gl.isContextLost();

Type guard

const isHealthyContext = (gl: WebGL2RenderingContext | null): gl is WebGL2RenderingContext =>
  !!gl && !gl.isContextLost();

Try / catch

canvas.addEventListener('webglcontextlost', (e) => e.preventDefault());
try {
  state = setupLightTrail(canvas);
} catch (err) {
  state = null; // fall back to non-effect render
}

Prevention

When it happens

Trigger: Calling setup after the GL context entered a lost state; allocating many programs in the same session until handles are exhausted; an OOM spike right after shader compilation succeeded.

Common situations: Many effects initialized in one render worker session without tearing down; headless Chromium with flaky GPU; a prior uncaught GL error leaving the context unusable.

Related errors


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