{"record":{"id":"387decb2c2cb16ba","repo":"stride3d/stride","slug":"invalid-swizzle-character-c","errorCode":null,"errorMessage":"Invalid swizzle character '{c}'","messagePattern":"Invalid swizzle character '(.+?)'","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"sources/shaders/Stride.Shaders.Parsers/Parsing/SDSL/AST/Expression.cs","lineNumber":1532,"sourceCode":"        var textureCoordSize = textureType.CoordinateDimension + (hasLod ? 1 : 0);\n        spirvValue = builder.Convert(context, spirvValue, baseType.GetVectorOrScalar(textureCoordSize));\n        return spirvValue;\n    }\n\n    SpirvValue ConvertOffset(SpirvContext context, SpirvBuilder builder, TextureType textureType, SpirvValue spirvValue)\n    {\n        spirvValue = builder.Convert(context, spirvValue, ScalarType.Int.GetVectorOrScalar(textureType.BaseDimension));\n        return spirvValue;\n    }\n\n    private static int ConvertSwizzle(char c)\n        => c switch\n        {\n            'x' or 'r' => 0,\n            'y' or 'g' => 1,\n            'z' or 'b' => 2,\n            'w' or 'a' => 3,\n            _ => throw new InvalidOperationException($\"Invalid swizzle character '{c}'\"),\n        };\n\n    public override string ToString() => ToString(Accessors.Count);\n\n    public string ToString(int accessorCount)\n    {\n        var builder = new StringBuilder().Append(Source);\n        for (int i = 0; i < accessorCount; i++)\n        {\n            Expression? a = Accessors[i];\n            if (a is IndexerExpression)\n                builder.Append(a);\n            else if (a is PostfixIncrement)\n                builder.Append(a);\n            else\n                builder.Append('.').Append(a);\n        }\n","sourceCodeStart":1514,"sourceCodeEnd":1550,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/shaders/Stride.Shaders.Parsers/Parsing/SDSL/AST/Expression.cs#L1514-L1550","documentation":"Swizzle components must be one of x/y/z/w or r/g/b/a; this helper maps each character to its component index (0–3). Any other character in a swizzle accessor throws InvalidOperationException at Expression.cs:1532.","triggerScenarios":"Writing a swizzle like `v.q`, `v.0`, or any character outside {x,y,z,w,r,g,b,a} on a vector value in SDSL shader code.","commonSituations":"Typos in swizzle names, copying GLSL/HLSL code that uses unsupported swizzle letters, or mixing rgba and xyzw incorrectly (e.g. `v.xg` is fine but `v.q` is not).","solutions":["Correct the swizzle character to x/y/z/w (or the equivalent r/g/b/a).","Remember only 4-component letters are valid; for larger types index components individually or use supported accessors.","If the swizzle looks right, check for invisible/typo characters (e.g. digits or unicode lookalikes) in the shader source."],"exampleFix":"// before\nfloat4 v; float f = v.q;\n// after\nfloat4 v; float f = v.w;","handlingStrategy":"validation","validationCode":"// validate swizzle characters before compiling\nbool valid = swizzle.All(c => \"xyzwrgba\".Contains(c));\nif (!valid) throw new ShaderCompileHint($\"Bad swizzle: {swizzle}\");","typeGuard":"static bool IsValidSwizzleChar(char c) => c is 'x' or 'y' or 'z' or 'w' or 'r' or 'g' or 'b' or 'a';","tryCatchPattern":"try { result = CompileExpression(expr, table, compiler); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"Invalid swizzle character\"))\n{ diagnostics.Report(expr.Info, ex.Message); }","preventionTips":["Use only x/y/z/w or r/g/b/a letters in swizzles.","Watch for typos and digit characters in swizzle names.","Add a lexer/parser-level check that rejects invalid swizzle characters with a friendlier message."],"tags":["shader","sdsl","swizzle","invalid-character"],"backgroundTag":"invalid-argument-value","analyzedSha":"96fad776d210c221682aac1ccdf4c79dc046fc38","analyzedAt":"2026-09-14T02:59:31.279Z","contentChangedAt":"2026-09-14T02:59:31.279Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}