{"record":{"id":"17a507caba56a12b","repo":"remotion-dev/remotion","slug":"failed-to-create-webgl-texture","errorCode":null,"errorMessage":"Failed to create WebGL texture","messagePattern":"Failed to create WebGL texture","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/brand/src/effects/metallic-swirl-effect.ts","lineNumber":580,"sourceCode":"\t\tif (!vbo) {\n\t\t\tthrow new Error('Failed to create WebGL buffer');\n\t\t}\n\n\t\tgl.bindBuffer(gl.ARRAY_BUFFER, vbo);\n\t\tgl.bufferData(gl.ARRAY_BUFFER, data, gl.STATIC_DRAW);\n\n\t\tconst aPos = gl.getAttribLocation(program, 'aPos');\n\t\tconst aUv = gl.getAttribLocation(program, 'aUv');\n\t\tgl.enableVertexAttribArray(aPos);\n\t\tgl.vertexAttribPointer(aPos, 2, gl.FLOAT, false, 16, 0);\n\t\tgl.enableVertexAttribArray(aUv);\n\t\tgl.vertexAttribPointer(aUv, 2, gl.FLOAT, false, 16, 8);\n\n\t\tgl.bindVertexArray(null);\n\n\t\tconst texture = gl.createTexture();\n\t\tif (!texture) {\n\t\t\tthrow new Error('Failed to create WebGL texture');\n\t\t}\n\n\t\tgl.bindTexture(gl.TEXTURE_2D, texture);\n\t\tgl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);\n\t\tgl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);\n\t\tgl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);\n\t\tgl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);\n\t\tgl.bindTexture(gl.TEXTURE_2D, null);\n\n\t\treturn {\n\t\t\tgl,\n\t\t\tprogram,\n\t\t\tvao,\n\t\t\tvbo,\n\t\t\ttexture,\n\t\t\tuSource: gl.getUniformLocation(program, 'uSource'),\n\t\t\tuResolution: gl.getUniformLocation(program, 'uResolution'),\n\t\t\tuTime: gl.getUniformLocation(program, 'uTime'),","sourceCodeStart":562,"sourceCodeEnd":598,"githubUrl":"https://github.com/remotion-dev/remotion/blob/78fe4bb3fdb5a2cd68724393d63cb223db333fa7/packages/brand/src/effects/metallic-swirl-effect.ts#L562-L598","documentation":"Thrown by the metallic-swirl effect's WebGL setup when gl.createTexture() returns null. WebGL returns null (rather than throwing) when the GL context is lost, when GPU resources/texture memory are exhausted, or when the implementation cannot allocate the object. The effect's init path has already built the program, VAO and VBO, so failure here is specifically a texture-allocation/context-health problem.","triggerScenarios":"Calling the metallic-swirl effect's create/init routine while gl.isContextLost() is true, after allocating many concurrent WebGL contexts/textures, or running under a software rasterizer (e.g. swiftshader/headless) that cannot service the request. Also when the canvas/context was forcibly lost by the browser (driver reset, tab backgrounding).","commonSituations":"Headless or server-side rendering without real GPU acceleration; stacking many WebGL-based brand effects simultaneously; GPU driver crash/reset mid-render; running in a VM/container with no GPU; Chrome losing the context during long renders.","solutions":["Check gl.isContextLost() before allocating, and recreate the WebGL context (listen for the 'webglcontextlost'/'webglcontextrestored' events) before retrying.","Reduce the number of concurrent WebGL contexts/effects and free unused textures with gl.deleteTexture() to lower memory pressure.","Render in a GPU-enabled environment (real Chrome with hardware acceleration on) rather than pure software rasterization.","Retry the effect init once after re-acquiring a healthy context; if it still fails, surface a clearer 'WebGL context unavailable' message to the user."],"exampleFix":"// before\nconst texture = gl.createTexture();\nif (!texture) {\n\tthrow new Error('Failed to create WebGL texture');\n}\n\n// after\nif (gl.isContextLost()) {\n\tthrow new Error('WebGL context is lost; recreate the context before applying the metallic-swirl effect');\n}\nconst texture = gl.createTexture();\nif (!texture) {\n\tthrow new Error('Failed to create WebGL texture (GPU resources exhausted or context lost)');\n}","handlingStrategy":"validation","validationCode":"// Run before invoking the metallic-swirl effect init\nconst assertWebGLHealthy = (gl: WebGL2RenderingContext | WebGLRenderingContext) => {\n  if (gl.isContextLost()) {\n    throw new Error('WebGL context is lost — recreate the context before using GPU effects');\n  }\n};\n// canvas.addEventListener('webglcontextrestored', reinitEffect);","typeGuard":"const isHealthyWebGLContext = (gl: unknown): gl is WebGL2RenderingContext =>\n  !!gl && typeof (gl as WebGL2RenderingContext).isContextLost === 'function' &&\n  !(gl as WebGL2RenderingContext).isContextLost();","tryCatchPattern":"try {\n  effect.create(canvas);\n} catch (err) {\n  if (String(err?.message ?? '').includes('Failed to create WebGL texture')) {\n    // wait for 'webglcontextrestored', then retry once\n  } else throw err;\n}","preventionTips":["Listen for webglcontextlost/webglcontextrestored and tear down / re-init GPU resources accordingly.","Limit the number of simultaneously active WebGL contexts/effects.","Render in a hardware-accelerated browser; avoid pure software rasterizers for GPU effects.","Free textures and buffers with gl.deleteTexture / gl.deleteBuffer when an effect is unmounted."],"tags":["webgl","gpu","textures","rendering","brand","context-loss"],"backgroundTag":null,"analyzedSha":"78fe4bb3fdb5a2cd68724393d63cb223db333fa7","analyzedAt":"2026-08-12T17:18:50.444Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}