{"record":{"id":"3574aa7ad9b8dc63","repo":"remotion-dev/remotion","slug":"failed-to-create-webgl-texture-3574aa","errorCode":null,"errorMessage":"Failed to create WebGL texture","messagePattern":"Failed to create WebGL texture","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"critical","filePath":"packages/effects/src/barrel-distortion/barrel-distortion-runtime.ts","lineNumber":80,"sourceCode":"};\n\nconst createProgram = (\n\tgl: WebGL2RenderingContext,\n\tvertexSource: string,\n\tfragmentSource: string,\n): WebGLProgram => {\n\tconst vs = compileShader(gl, gl.VERTEX_SHADER, vertexSource);\n\tconst fs = compileShader(gl, gl.FRAGMENT_SHADER, fragmentSource);\n\tconst program = linkProgram(gl, vs, fs);\n\tgl.deleteShader(vs);\n\tgl.deleteShader(fs);\n\treturn program;\n};\n\nconst createRgbaTexture = (gl: WebGL2RenderingContext): WebGLTexture => {\n\tconst texture = gl.createTexture();\n\tif (!texture) {\n\t\tthrow new Error('Failed to create WebGL texture');\n\t}\n\n\tgl.bindTexture(gl.TEXTURE_2D, texture);\n\tgl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);\n\tgl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);\n\tgl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);\n\tgl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);\n\tgl.bindTexture(gl.TEXTURE_2D, null);\n\treturn texture;\n};\n\nexport const setupBarrelDistortion = (\n\ttarget: HTMLCanvasElement,\n): BarrelDistortionState => {\n\tconst gl = target.getContext('webgl2', {\n\t\tpremultipliedAlpha: true,\n\t\talpha: true,\n\t\tpreserveDrawingBuffer: true,","sourceCodeStart":62,"sourceCodeEnd":98,"githubUrl":"https://github.com/remotion-dev/remotion/blob/78fe4bb3fdb5a2cd68724393d63cb223db333fa7/packages/effects/src/barrel-distortion/barrel-distortion-runtime.ts#L62-L98","documentation":"Thrown by `createRgbaTexture` in the barrel distortion runtime when `gl.createTexture()` returns `null`. WebGL returns null for resource allocations when the context is lost, GPU memory is exhausted, or too many textures are already allocated. This is an environmental/resource failure, not a logic error in the effect.","triggerScenarios":"Called from `setupBarrelDistortion` -> `createRgbaTexture(gl)` on line 78. Fires when `gl.createTexture()` yields a null WebGLTexture handle.","commonSituations":"Too many concurrent WebGL contexts/canvases in one Studio render (each effect setup holds GPU resources); GPU memory pressure from very large frame textures; a WebGL context lost event that has not been handled; running in an environment with a constrained software renderer.","solutions":["Reduce the number of simultaneously active WebGL-backed effects; call the effect's `cleanup` (cleanupBarrelDistortion) to release textures before creating new ones.","Check for a lost WebGL context (`gl.isContextLost()`) and reinitialize the effect on restore.","Lower frame resolution to reduce texture memory pressure.","Ensure hardware acceleration is enabled in the browser/headless Chrome used for rendering.","Update GPU drivers; older drivers leak texture handles and eventually return null."],"exampleFix":"// before: setup once, never release\nconst state = setupBarrelDistortion(canvas);\n// ...\n\n// after: release when the canvas/effect is no longer needed\ncleanupBarrelDistortion(state);","handlingStrategy":"try-catch","validationCode":"if (gl.isContextLost()) { /* skip, await restore */ }","typeGuard":null,"tryCatchPattern":"try {\n  const state = setupBarrelDistortion(canvas);\n} catch (err) {\n  if (/Failed to create WebGL texture/.test(err.message)) {\n    // reduce active effects or await context restore, then retry\n  } else { throw err; }\n}","preventionTips":["Call cleanupBarrelDistortion when an effect is no longer needed.","Listen for `webglcontextlost` and stop allocating until `webglcontextrestored`.","Limit the number of concurrently active WebGL effects in a single render."],"tags":["webgl2","texture","gpu-memory","barrel-distortion","resource-exhaustion"],"backgroundTag":null,"analyzedSha":"78fe4bb3fdb5a2cd68724393d63cb223db333fa7","analyzedAt":"2026-08-12T17:18:50.444Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}