{"record":{"id":"b174e6ab5181132e","repo":"remotion-dev/remotion","slug":"failed-to-create-webgl-program-b174e6","errorCode":null,"errorMessage":"Failed to create WebGL program","messagePattern":"Failed to create WebGL program","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/effects/src/barrel-distortion/barrel-distortion-runtime.ts","lineNumber":49,"sourceCode":"\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 => {\n\tconst program = gl.createProgram();\n\tif (!program) {\n\t\tthrow new Error('Failed to create WebGL program');\n\t}\n\n\tgl.attachShader(program, vs);\n\tgl.attachShader(program, fs);\n\tgl.linkProgram(program);\n\tif (!gl.getProgramParameter(program, gl.LINK_STATUS)) {\n\t\tconst log = gl.getProgramInfoLog(program);\n\t\tgl.deleteProgram(program);\n\t\tthrow new Error(`Program link failed: ${log ?? '(no log)'}`);\n\t}\n\n\treturn program;\n};\n\nconst createProgram = (\n\tgl: WebGL2RenderingContext,\n\tvertexSource: string,\n\tfragmentSource: string,","sourceCodeStart":31,"sourceCodeEnd":67,"githubUrl":"https://github.com/remotion-dev/remotion/blob/78fe4bb3fdb5a2cd68724393d63cb223db333fa7/packages/effects/src/barrel-distortion/barrel-distortion-runtime.ts#L31-L67","documentation":"Thrown by `linkProgram` in the barrel-distortion WebGL runtime when `gl.createProgram()` returns null. Like createShader returning null, this means the WebGL2 context could not allocate a program object — context loss, invalid context, or resource exhaustion. The check runs before attachShader/linkProgram.","triggerScenarios":"After both shaders compile successfully, `linkProgram` calls `gl.createProgram()` on a context that returns null. Same root causes as error 457: lost/invalid WebGL2 context or GPU resource exhaustion.","commonSituations":"Context lost between shader compile and program creation; too many programs allocated; headless/GPU-less environment; driver crash mid-render of the barrel-distortion effect.","solutions":["Handle `webglcontextlost`/`webglcontextrestored` and recreate the program on restore.","Render in an environment with reliable WebGL2 (Chromium + GPU/SwiftShader).","Limit concurrent effect instances to avoid exhausting program objects.","Retry the render after the context is restored."],"exampleFix":"// before\neffect.init(canvas); // createProgram 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 program = gl.createProgram();\nif (!program) throw new Error('context lost; recreate before linking');","typeGuard":"const canCreateProgram = (gl: WebGL2RenderingContext): boolean =>\n  gl.createProgram() !== null;","tryCatchPattern":"try {\n  linkProgram(gl, vs, fs);\n} catch (e) {\n  if (/Failed to create WebGL program/.test(String(e))) {\n    await waitForContextRestore(canvas); linkProgram(gl, vs, fs);\n  } else throw e;\n}","preventionTips":["Handle webglcontextlost/restored and recreate programs on restore.","Render on WebGL2-capable environments.","Limit concurrent programs to stay within GPU limits."],"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"}