BabylonJS/Babylon.js · error · Error
"Uniform line not found"
Error message
"Uniform line not found"
What it means
ParseFragmentShader matches uniform declarations with an annotation regex; group 1 is the optional JSON annotation and group 2 is the uniform declaration line. If the regex matched but the uniform line itself is empty, the annotation is malformed/unattached, so this error is thrown.
Source
Thrown at packages/dev/smartFilters/src/utils/buildTools/shaderConverter.ts:134
* @param fragmentShader - The fragment shader to process
* @returns The processed fragment shader
*/
export function ParseFragmentShader(fragmentShader: string): FragmentShaderInfo {
const { header, fragmentShaderWithoutHeader } = ReadHeader(fragmentShader);
fragmentShader = fragmentShaderWithoutHeader;
const blockType = header?.[SmartFilterBlockTypeKey] || undefined;
const namespace = header?.namespace || null;
// Read the uniforms
const uniforms: UniformMetadata[] = [];
const uniformRegExp = new RegExp(/(\/\/\s*\{.*\}\s*(?:\r\n|\r|\n)+)?(uniform .*)/gm);
const uniformGroups = fragmentShader.matchAll(uniformRegExp);
for (const matches of uniformGroups) {
const annotationJSON = matches[1];
const uniformLine = matches[2];
if (!uniformLine) {
throw new Error("Uniform line not found");
}
const uniformLineMatches = new RegExp(/^uniform\s+(\w+)\s+(\w+)\s*;?/gm).exec(uniformLine);
if (!uniformLineMatches || uniformLineMatches.length < 3) {
throw new Error(`Uniforms must have a type and a name: '${uniformLine}'`);
}
const uniformTypeString = uniformLineMatches[1];
const uniformName = uniformLineMatches[2];
if (!uniformTypeString) {
throw new Error(`Uniforms must have a type: '${uniformLine}'`);
}
if (!uniformName) {
throw new Error(`Uniforms must have a name: '${uniformLine}'`);
}
// Convert to ConnectionPointType
let type: ConnectionPointType;
View on GitHub (pinned to 0592b347b8)
Solutions
- Ensure every uniform annotation is directly followed by a valid 'uniform <type> <name>;' line.
- Remove orphaned annotation comments that no longer precede a uniform.
- Check line endings/formatting so the uniform statement is on the line after the annotation.
Example fix
// before
/// {"autoBind": true}
// after
/// {"autoBind": true}
uniform float textureWidth; Defensive patterns
Strategy: validation
Validate before calling
// Each '/// {...}' annotation must be immediately followed by a uniform line
const lines = fs.readFileSync(glslPath, 'utf8').split('\n');
lines.forEach((l, i) => { if (/^\s*\/\/\/\s*\{/.test(l) && !/^\s*uniform\b/.test(lines[i+1] ?? '')) console.error(`Orphan annotation at line ${i+1} of ${glslPath}`); }); Try / catch
try { await ConvertShader(path, ...); } catch (e) { if (e.message.includes('Uniform line not found')) { fixOrphanAnnotation(path); } else { throw e; } } Prevention
- Always pair annotation comments with the uniform on the next line.
- Delete annotations when deleting their uniform.
- Lint for orphan '///' JSON comments.
When it happens
Trigger: A uniform annotation comment (e.g. /// {"x":...}) immediately followed by an empty or missing 'uniform' declaration line, so the regex's second capture group is empty.
Common situations: Annotation comment left behind after the uniform line was deleted; comment formatting broke the uniform match; template generation emitted an annotation without the uniform.
Related errors
- `Uniforms must have a type and a name: '${uniformLine}'`
- `Uniforms must have a type: '${uniformLine}'`
- `Uniforms must have a name: '${uniformLine}'`
- `Unsupported uniform type: '${uniformTypeString}'`
- VERTEX SHADER ${log}
AI-assisted analysis of BabylonJS/Babylon.js@0592b347b8 (2026-08-30).
Data as JSON: /api/errors/eb892582dd4989c0.
Report an issue: GitHub.