remotion-dev/remotion · critical · Error
Failed to create WebGL shader
Error message
Failed to create WebGL shader
What it means
Thrown by compileShader (packages/effects/src/paper.ts:657) when gl.createShader(type) returns null while compiling PAPER_VS or PAPER_FS. As with the other null GL-object returns, it indicates a lost WebGL2 context or exhausted shader-object budget; the shader source is not the cause at this line.
Source
Thrown at packages/effects/src/paper.ts:657
vec3 paperTone = mix(backRgb, frontRgb, clamp(res, 0.0, 1.0));
vec3 texturedRgb = displacedRgb * (0.72 + 0.42 * res);
texturedRgb = mix(texturedRgb, texturedRgb * paperTone, 0.65);
texturedRgb -= 0.007 * dropPattern;
texturedRgb = mix(sourceRgb, texturedRgb, frame);
vec3 finalRgb = mix(sourceRgb, clamp(texturedRgb, 0.0, 1.0), uAmount);
fragColor = vec4(finalRgb * sourceAlpha, sourceAlpha);
}
`;
const compileShader = (
gl: WebGL2RenderingContext,
type: number,
source: string,
): WebGLShader => {
const shader = gl.createShader(type);
if (!shader) {
throw new Error('Failed to create WebGL shader');
}
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(`Paper shader compile failed: ${log ?? '(no log)'}`);
}
return shader;
};
const linkProgram = (
gl: WebGL2RenderingContext,
vs: WebGLShader,
fs: WebGLShader,
): WebGLProgram => {View on GitHub (pinned to 78fe4bb3fd)
Solutions
- Render on a GPU host with WebGL enabled in headless Chrome.
- Handle 'webglcontextlost' and re-run setup after 'webglcontextrestored'.
- Reduce concurrent WebGL2 effects so the shader budget is not exhausted.
Example fix
// before
const fs = compileShader(gl, gl.FRAGMENT_SHADER, PAPER_FS); // createShader() returned null
// after
if (gl.isContextLost()) {
throw new Error('WebGL2 context lost before paper setup');
} Defensive patterns
Strategy: try-catch
Validate before calling
function canCompilePaperShader(): boolean {
try {
const c = document.createElement('canvas');
const gl = c.getContext('webgl2');
if (!gl || gl.isContextLost()) return false;
const s = gl.createShader(gl.VERTEX_SHADER);
const ok = !!s;
if (s) gl.deleteShader(s);
return ok;
} catch {
return false;
}
} Try / catch
try {
scene.push(paper({amount: 1}));
} catch (err) {
if (/Failed to create WebGL shader/.test(String(err?.message))) {
// context unhealthy: skip paper and retry after restore
} else throw err;
} Prevention
- Render on a GPU host with WebGL enabled in headless Chrome.
- Handle webglcontextlost and re-run setup after webglcontextrestored.
- Do not reuse a context after a loss without re-running setup.
When it happens
Trigger: setupPaper compiling shaders on a lost context or after too many live shaders; running the paper effect after a context loss that was not handled.
Common situations: GPU process crash mid-render; render host without usable WebGL2; heavy parallel renders exhausting GL objects.
Related errors
- Failed to create WebGL shader
- Paper shader compile failed: ${log ?? '(no log)'}
- Failed to create WebGL program
- Failed to create WebGL texture
- Failed to create WebGL noise texture
AI-assisted analysis of remotion-dev/remotion@78fe4bb3fd (2026-08-12).
Data as JSON: /api/errors/f955172027890e63.
Report an issue: GitHub.