{"record":{"id":"fcb26412e9006a35","repo":"BabylonJS/Babylon.js","slug":"unable-to-create-program-fcb264","errorCode":null,"errorMessage":"Unable to create program","messagePattern":"Unable to create program","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"critical","filePath":"packages/dev/core/src/Engines/thinEngine.functions.ts","lineNumber":174,"sourceCode":"    return pipelineContext;\r\n}\r\n\r\n/**\r\n * @internal\r\n */\r\nexport function _createShaderProgram(\r\n    pipelineContext: WebGLPipelineContext,\r\n    vertexShader: WebGLShader,\r\n    fragmentShader: WebGLShader,\r\n    context: WebGLContext,\r\n    _transformFeedbackVaryings: Nullable<string[]> = null,\r\n    validateShaderPrograms?: boolean\r\n): WebGLProgram {\r\n    const shaderProgram = context.createProgram();\r\n    pipelineContext.program = shaderProgram;\r\n\r\n    if (!shaderProgram) {\r\n        throw new Error(\"Unable to create program\");\r\n    }\r\n\r\n    context.attachShader(shaderProgram, vertexShader);\r\n    context.attachShader(shaderProgram, fragmentShader);\r\n\r\n    context.linkProgram(shaderProgram);\r\n\r\n    pipelineContext.context = context;\r\n    pipelineContext.vertexShader = vertexShader;\r\n    pipelineContext.fragmentShader = fragmentShader;\r\n\r\n    if (!pipelineContext.isParallelCompiled) {\r\n        _finalizePipelineContext(pipelineContext, context, validateShaderPrograms);\r\n    }\r\n\r\n    return shaderProgram;\r\n}\r\n\r","sourceCodeStart":156,"sourceCodeEnd":192,"githubUrl":"https://github.com/BabylonJS/Babylon.js/blob/0592b347b8a4ee0236089ea86a749cacfdb266d8/packages/dev/core/src/Engines/thinEngine.functions.ts#L156-L192","documentation":"_createShaderProgram calls context.createProgram(); if the WebGL context returns null the engine throws \"Unable to create program\". Null from createProgram means the driver could not allocate a program object — typically a lost context or GPU resource exhaustion.","triggerScenarios":"Compiling/linking a shader effect when gl.createProgram() returns null: context lost after device removal, too many live programs, or driver OOM.","commonSituations":"Tab backgrounded/GPU process crashed during effect compilation, mobile device under memory pressure with hundreds of unique shaders, context restored without rebuilding engine state.","solutions":["Check gl.isContextLost(); if lost, wait for webglcontextrestored and rebuild the engine/effect cache.","Reduce shader program count: merge effects, reuse materials, and dispose unused effects.","Retry effect creation after resources are released.","Catch the error at the scene/effect level and fall back to a simpler material."],"exampleFix":"// before\nconst effect = new Effect(shaderName, attrs, uniforms, engine);\n// after\ntry {\n  const effect = new Effect(shaderName, attrs, uniforms, engine);\n} catch (e) {\n  if (/Unable to create program/.test(e.message) && engine._gl.isContextLost()) {\n    await contextRestoredPromise;\n    effect = new Effect(shaderName, attrs, uniforms, engine);\n  }\n}","handlingStrategy":"retry","validationCode":"if (engine._gl.isContextLost()) {\n  await new Promise(r => engine._gl.getExtension('') ?? r); // or listen for webglcontextrestored first\n}","typeGuard":"function isEngineContextAlive(engine) {\n  const gl = (engine as any)._gl;\n  return !!gl && !gl.isContextLost();\n}","tryCatchPattern":"try {\n  effect = new Effect(name, attrs, uniforms, engine);\n} catch (e) {\n  if (/Unable to create program/.test(e.message)) {\n    await contextRestored(engine);\n    effect = new Effect(name, attrs, uniforms, engine);\n  }\n}","preventionTips":["Install webglcontextlost/restored handlers that rebuild the effect cache.","Limit unique shader permutations (variant explosion).","Dispose effects of removed materials."],"tags":["webgl","shaders","context-loss","resource-exhaustion"],"backgroundTag":"gpu-program-allocation-failed","analyzedSha":"0592b347b8a4ee0236089ea86a749cacfdb266d8","analyzedAt":"2026-08-30T15:11:20.442Z","schemaVersion":2},"datasetVersion":"2026-08-30T18:17:15.746Z"}