{"record":{"id":"f86903164355c7ec","repo":"BabylonJS/Babylon.js","slug":"shader-program-not-found-for-block-block-name","errorCode":null,"errorMessage":"Shader program not found for block \"${block.name}\"!","messagePattern":"Shader program not found for block \"(.+?)\"!","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/dev/smartFilters/src/optimization/smartFilterOptimizer.ts","lineNumber":550,"sourceCode":"    }\r\n\r\n    // Processes a block given one of its output connection point\r\n    // Returns the name of the main function in the shader code\r\n    private _optimizeBlock(optimizedBlock: OptimizedShaderBlock, outputConnectionPoint: ConnectionPoint, samplers: string[]): string {\r\n        const block = outputConnectionPoint.ownerBlock;\r\n\r\n        if (!(block instanceof ShaderBlock)) {\r\n            throw `Unhandled block type! blockType=${block.blockType}`;\r\n        }\r\n\r\n        if (this._currentOutputTextureOptions === undefined) {\r\n            this._currentOutputTextureOptions = block.outputTextureOptions;\r\n        }\r\n\r\n        // Sometimes getShaderProgram() does work, so only grab it once for efficiency\r\n        const shaderProgram = block.getShaderProgram();\r\n        if (!shaderProgram) {\r\n            throw new Error(`Shader program not found for block \"${block.name}\"!`);\r\n        }\r\n\r\n        this._vertexShaderCode = this._vertexShaderCode ?? shaderProgram.vertex;\r\n\r\n        // The operations we collect which we will apply to all functions of this block later\r\n        const renameWork: RenameWork = {\r\n            symbolRenames: [],\r\n            samplerRenames: [],\r\n            sampleToFunctionCallSwaps: [],\r\n            samplersToApplyAutoTo: [],\r\n        };\r\n\r\n        // Generates a unique name for the fragment main function (if not already generated)\r\n        const shaderFuncName = shaderProgram.fragment.mainFunctionName;\r\n\r\n        let newShaderFuncName = this._blockToMainFunctionName.get(block);\r\n\r\n        if (!newShaderFuncName) {\r","sourceCodeStart":532,"sourceCodeEnd":568,"githubUrl":"https://github.com/BabylonJS/Babylon.js/blob/0592b347b8a4ee0236089ea86a749cacfdb266d8/packages/dev/smartFilters/src/optimization/smartFilterOptimizer.ts#L532-L568","documentation":"SmartFilterOptimizer._optimizeBlock needs the block's GLSL shader program to rewrite and inline it. It calls block.getShaderProgram(), and if that returns null/undefined it throws this error naming the block. A block that cannot produce its shader program cannot be optimized.","triggerScenarios":"getShaderProgram() returning null because the block's effect was never compiled (engine context missing, shader not yet built), the block is a custom block that failed to provide shader code, or the runtime data for the block is not initialized.","commonSituations":"Calling OptimizeAsync before the filter's effects were built; a custom block whose getShaderProgram depends on runtime state that isn't ready; shader compilation failing silently upstream so the program is null.","solutions":["Ensure the filter runtime is initialized (effects compiled) before running the optimizer.","Check the block's getShaderProgram implementation/inputs — verify the shader code (vertex/fragment) is provided and valid.","Confirm the block's runtime data exists in the runtime data map for the current runtime.","Fix any earlier shader compile errors that leave the program unset."],"exampleFix":"// before\nawait optimizer.run(); // effects not built yet -> null program\n// after\nawait smartFilter.build(); // or attach the filter so effects compile first\nawait SmartFilterOptimizer.OptimizeAsync(engine, smartFilter, texture);","handlingStrategy":"validation","validationCode":"for (const block of filter.allBlocks) {\n  if (block.getShaderProgram && !block.getShaderProgram()) {\n    throw new Error(`Block \"${block.name}\" has no shader program; build the filter first`);\n  }\n}","typeGuard":"function hasShaderProgram(b: BaseBlock): b is BaseBlock & { getShaderProgram(): IShaderProgram } {\n  return !!(b as OptimizedBlock).getShaderProgram?.();\n}","tryCatchPattern":"try {\n  const rd = await SmartFilterOptimizer.OptimizeAsync(engine, filter, texture);\n} catch (e) {\n  if (e.message.startsWith(\"Shader program not found for block\")) {\n    await filter.build(); // ensure effects are compiled, then retry once\n  } else throw e;\n}","preventionTips":["Build/attach the filter so shader effects are compiled before optimizing.","For custom blocks, ensure getShaderProgram always returns valid code or null with a clear upstream error.","Fix shader compile errors that leave programs null before optimizing."],"tags":["optimization","shader-program","initialization-order"],"backgroundTag":"shader-program-not-found","analyzedSha":"0592b347b8a4ee0236089ea86a749cacfdb266d8","analyzedAt":"2026-08-30T15:11:20.442Z","schemaVersion":2},"datasetVersion":"2026-08-30T18:17:15.746Z"}