{"record":{"id":"0c89d08422358081","repo":"remotion-dev/remotion","slug":"failed-to-create-webgl-shader-0c89d0","errorCode":null,"errorMessage":"Failed to create WebGL shader","messagePattern":"Failed to create WebGL shader","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/effects/src/barrel-distortion/barrel-distortion-runtime.ts","lineNumber":28,"sourceCode":"\tgl: WebGL2RenderingContext;\n\tprogram: WebGLProgram;\n\tvao: WebGLVertexArrayObject;\n\tvbo: WebGLBuffer;\n\ttextureSource: WebGLTexture;\n\tuniforms: {\n\t\tuSource: WebGLUniformLocation | null;\n\t\tuAmount: WebGLUniformLocation | null;\n\t};\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(`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":10,"sourceCodeEnd":46,"githubUrl":"https://github.com/remotion-dev/remotion/blob/78fe4bb3fdb5a2cd68724393d63cb223db333fa7/packages/effects/src/barrel-distortion/barrel-distortion-runtime.ts#L10-L46","documentation":"Thrown by `compileShader` in the barrel-distortion WebGL runtime when `gl.createShader(type)` returns null. A null return indicates the WebGL2 context could not allocate a shader object — typically because the context is lost, the context is not actually a WebGL2 context, or too many resources are allocated. The check happens before shaderSource/compile.","triggerScenarios":"The barrel-distortion effect's `compileShader` is called on a WebGL2RenderingContext that is lost or invalid, so `createShader` yields null. This can occur when the canvas context was lost (webglcontextlost event), the GPU process crashed, or the context was retrieved as WebGL1 by mistake.","commonSituations":"Rendering the barrel-distortion effect on a machine/driver with flaky WebGL2; context loss during a long render; running in a headless browser without GPU/WebGL2 support; too many simultaneous effect instances exhausting GPU memory.","solutions":["Ensure the canvas acquires a `webgl2` context and handle `webglcontextlost` by recreating the effect state.","Run the render on an environment with WebGL2 support (Chromium with GPU, or SwiftShader).","Reduce the number of concurrent WebGL effect instances to stay within GPU memory.","Retry the render on context restore rather than failing immediately."],"exampleFix":"// before\neffect.init(canvas); // createShader returned null\n\n// after\ncanvas.addEventListener('webglcontextrestored', () => effect.init(canvas));\ncanvas.addEventListener('webglcontextlost', (e) => e.preventDefault());","handlingStrategy":"validation","validationCode":"const gl = canvas.getContext('webgl2');\nif (!gl) throw new Error('WebGL2 unavailable');\nconst shader = gl.createShader(gl.VERTEX_SHADER);\nif (!shader) throw new Error('context may be lost; recreate it');","typeGuard":"const hasValidWebGL2 = (canvas: HTMLCanvasElement): boolean =>\n  canvas.getContext('webgl2') instanceof WebGL2RenderingContext;","tryCatchPattern":"try {\n  effect.init(canvas);\n} catch (e) {\n  if (/Failed to create WebGL shader/.test(String(e))) {\n    await waitForContextRestore(canvas); effect.init(canvas);\n  } else throw e;\n}","preventionTips":["Acquire a webgl2 context explicitly and handle webglcontextlost/restored.","Render on WebGL2-capable environments (Chromium + GPU/SwiftShader).","Limit concurrent effect instances to avoid GPU exhaustion."],"tags":["webgl","effects","barrel-distortion","gpu","context-loss"],"backgroundTag":null,"analyzedSha":"78fe4bb3fdb5a2cd68724393d63cb223db333fa7","analyzedAt":"2026-08-12T17:18:50.444Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}