{"record":{"id":"e3f1100c603e169e","repo":"BabylonJS/Babylon.js","slug":"uniforms-must-have-a-type-and-a-name-uniforml","errorCode":null,"errorMessage":"`Uniforms must have a type and a name: '${uniformLine}'`","messagePattern":"`Uniforms must have a type and a name: '(.+?)'`","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/dev/smartFilters/src/utils/buildTools/shaderConverter.ts","lineNumber":139,"sourceCode":"    fragmentShader = fragmentShaderWithoutHeader;\r\n    const blockType = header?.[SmartFilterBlockTypeKey] || undefined;\r\n    const namespace = header?.namespace || null;\r\n\r\n    // Read the uniforms\r\n    const uniforms: UniformMetadata[] = [];\r\n    const uniformRegExp = new RegExp(/(\\/\\/\\s*\\{.*\\}\\s*(?:\\r\\n|\\r|\\n)+)?(uniform .*)/gm);\r\n    const uniformGroups = fragmentShader.matchAll(uniformRegExp);\r\n    for (const matches of uniformGroups) {\r\n        const annotationJSON = matches[1];\r\n        const uniformLine = matches[2];\r\n\r\n        if (!uniformLine) {\r\n            throw new Error(\"Uniform line not found\");\r\n        }\r\n\r\n        const uniformLineMatches = new RegExp(/^uniform\\s+(\\w+)\\s+(\\w+)\\s*;?/gm).exec(uniformLine);\r\n        if (!uniformLineMatches || uniformLineMatches.length < 3) {\r\n            throw new Error(`Uniforms must have a type and a name: '${uniformLine}'`);\r\n        }\r\n        const uniformTypeString = uniformLineMatches[1];\r\n        const uniformName = uniformLineMatches[2];\r\n\r\n        if (!uniformTypeString) {\r\n            throw new Error(`Uniforms must have a type: '${uniformLine}'`);\r\n        }\r\n        if (!uniformName) {\r\n            throw new Error(`Uniforms must have a name: '${uniformLine}'`);\r\n        }\r\n\r\n        // Convert to ConnectionPointType\r\n        let type: ConnectionPointType;\r\n        switch (uniformTypeString) {\r\n            case \"float\":\r\n                type = ConnectionPointType.Float;\r\n                break;\r\n            case \"sampler2D\":\r","sourceCodeStart":121,"sourceCodeEnd":157,"githubUrl":"https://github.com/BabylonJS/Babylon.js/blob/0592b347b8a4ee0236089ea86a749cacfdb266d8/packages/dev/smartFilters/src/utils/buildTools/shaderConverter.ts#L121-L157","documentation":"After locating a uniform line, ParseFragmentShader parses it with /^uniform\\s+(\\w+)\\s+(\\w+)\\s*;?/. If the regex does not produce type and name captures, the declaration is malformed and this error reports the offending line verbatim.","triggerScenarios":"A 'uniform' statement that doesn't match 'uniform <type> <name>' — e.g. multi-line declarations, missing name, or non-word characters in type/name (arrays 'uniform float a[4];', structs).","commonSituations":"GLSL array or struct uniforms unsupported by the converter; uniforms split across lines; exotic GLSL type names; copy-pasted declarations with unusual spacing.","solutions":["Rewrite the uniform as a simple single-line 'uniform <type> <name>;' declaration.","Replace array/struct uniforms with individual scalar/vector uniforms supported by the tool.","Check the quoted line in the error message to find and fix the exact malformed statement."],"exampleFix":"// before\nuniform float weights[8];\n// after\nuniform float weight0;\nuniform float weight1;","handlingStrategy":"validation","validationCode":"/^uniform\\s+\\w+\\s+\\w+\\s*;?$/m.test(src) || lines.filter(l => /\\buniform\\b/.test(l) && !/^\\s*\\/\\//.test(l)).forEach(l => console.error(`Malformed uniform: ${l.trim()}`));","typeGuard":"const isWellFormedUniform = (line: string): boolean => /^uniform\\s+\\w+\\s+\\w+\\s*;?$/.test(line.trim());","tryCatchPattern":"try { await ConvertShader(path, ...); } catch (e) { const m = e.message.match(/Uniforms must have a type and a name: '(.*)'/); if (m) { rewriteUniform(m[1]); } else { throw e; } }","preventionTips":["Keep uniform declarations on one line.","Avoid array/struct uniforms in block shaders.","Check the line echoed in the error and fix it directly."],"tags":["glsl","uniform-parsing","syntax"],"backgroundTag":"uniform-declaration-malformed","analyzedSha":"0592b347b8a4ee0236089ea86a749cacfdb266d8","analyzedAt":"2026-08-30T15:11:20.442Z","schemaVersion":2},"datasetVersion":"2026-08-30T18:17:15.746Z"}