{"record":{"id":"d1248b80db818a53","repo":"remotion-dev/remotion","slug":"failed-to-create-webgl-shader-d1248b","errorCode":null,"errorMessage":"Failed to create WebGL shader","messagePattern":"Failed to create WebGL shader","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"critical","filePath":"packages/effects/src/gridlines.ts","lineNumber":365,"sourceCode":"\tvec4 line = uLineColor * coverage;\n\n\tif (uMaskToSourceAlpha) {\n\t\tfragColor = sourceAtop(sourceAtop(texColor, background), line);\n\t\treturn;\n\t}\n\n\tfragColor = sourceOver(sourceOver(texColor, background), line);\n}\n`;\n\nconst compileShader = (\n\tgl: WebGL2RenderingContext,\n\ttype: number,\n\tsource: string,\n): WebGLShader => {\n\tconst shader = gl.createShader(type);\n\tif (!shader) {\n\t\tthrow new Error('Failed to create WebGL shader');\n\t}\n\n\tgl.shaderSource(shader, source);\n\tgl.compileShader(shader);\n\tif (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {\n\t\tconst log = gl.getShaderInfoLog(shader);\n\t\tgl.deleteShader(shader);\n\t\tthrow new Error(`Gridlines shader compile failed: ${log ?? '(no log)'}`);\n\t}\n\n\treturn shader;\n};\n\nconst linkProgram = (\n\tgl: WebGL2RenderingContext,\n\tvs: WebGLShader,\n\tfs: WebGLShader,\n): WebGLProgram => {","sourceCodeStart":347,"sourceCodeEnd":383,"githubUrl":"https://github.com/remotion-dev/remotion/blob/78fe4bb3fdb5a2cd68724393d63cb223db333fa7/packages/effects/src/gridlines.ts#L347-L383","documentation":"Thrown by gridlines' compileShader (gridlines.ts:365) when gl.createShader(type) returns null. A null return means WebGL could not allocate a shader object, typically due to context loss or severe GPU resource exhaustion. The library throws immediately because subsequent shaderSource/compileShader calls would crash on null.","triggerScenarios":"Called during the Gridlines effect setup, after acquiring a WebGL2 context, for both the vertex and fragment shaders. Happens when the WebGL context is lost (e.g. GPU driver crash, too many contexts), the process has leaked GL objects, or the driver refuses new shader allocation.","commonSituations":"Long-running render that leaks contexts; multiple Studio previews/compositions open exhausting the GPU; a machine hitting a GPU-reset/context-loss; running on a driver/SwiftShader that caps shader count.","solutions":["Check the WebGL context for loss: register a webglcontextlost listener on the canvas and recreate the effect on restore.","Reduce the number of concurrent WebGL effects/compositions; ensure cleanup() is called so GL objects are freed.","Restart the headless browser/GPU; if persistent, update GPU drivers or switch ANGLE backend.","Confirm you are not creating new canvases/contexts in a render loop without disposing them."],"exampleFix":"// before: a new effect/canvas per frame with no cleanup -> eventual null allocation\nuseEffect(() => { makeEffect(); }, [frame]);\n\n// after: set up once, clean up on unmount, handle context loss\nuseEffect(() => {\n  const canvas = ref.current!;\n  const onLost = (e: Event) => { e.preventDefault(); /* recreate */ };\n  canvas.addEventListener('webglcontextlost', onLost);\n  const handle = setupOnce();\n  return () => { handle.cleanup(); canvas.removeEventListener('webglcontextlost', onLost); };\n}, []);","handlingStrategy":"try-catch","validationCode":"// Probe context health before relying on GL allocation\nconst lost = gl.isContextLost();\nif (lost) throw new Error('WebGL2 context lost before shader allocation');","typeGuard":"null","tryCatchPattern":"try {\n  gridlines.setup(canvas);\n} catch (e) {\n  if (e instanceof Error && e.message === 'Failed to create WebGL shader') {\n    // context loss / resource exhaustion: recreate context, reduce load\n  }\n  throw e;\n}","preventionTips":["Handle webglcontextlost/webglcontextrestored on the canvas.","Always pair setup() with cleanup() to free shaders.","Avoid creating new WebGL contexts in a render loop.","Limit concurrent WebGL compositions on constrained GPUs."],"tags":["webgl","gridlines-effect","shader","gpu","resource-exhaustion"],"backgroundTag":null,"analyzedSha":"78fe4bb3fdb5a2cd68724393d63cb223db333fa7","analyzedAt":"2026-08-12T17:18:50.444Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}