{"record":{"id":"e7bc0a0a58769043","repo":"stride3d/stride","slug":"unsupported-float-vector-size-v-length","errorCode":null,"errorMessage":"Unsupported float vector size: {v.Length}","messagePattern":"Unsupported float vector size: (.+?)","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"sources/shaders/Stride.Shaders.Compilers/SDSL/ShaderMixer.CBuffers.cs","lineNumber":641,"sourceCode":"        /// <summary>\n        /// Converts compiler-internal <see cref=\"ConstantVector\"/> to serializable CLR types\n        /// that the engine expects (Vector2/3/4, Int2/3/4, etc.).\n        /// Scalars (float, int, uint, bool) pass through unchanged.\n        /// </summary>\n        private static object? ConvertDefaultValue(object? value)\n        {\n            if (value is not ConstantVector cv)\n                return value;\n\n            var v = cv.Values;\n            return v[0] switch\n            {\n                float => v.Length switch\n                {\n                    2 => new Vector2((float)v[0], (float)v[1]),\n                    3 => new Vector3((float)v[0], (float)v[1], (float)v[2]),\n                    4 => (object)new Vector4((float)v[0], (float)v[1], (float)v[2], (float)v[3]),\n                    _ => throw new NotSupportedException($\"Unsupported float vector size: {v.Length}\"),\n                },\n                int => v.Length switch\n                {\n                    2 => new Int2((int)v[0], (int)v[1]),\n                    3 => new Int3((int)v[0], (int)v[1], (int)v[2]),\n                    4 => (object)new Int4((int)v[0], (int)v[1], (int)v[2], (int)v[3]),\n                    _ => throw new NotSupportedException($\"Unsupported int vector size: {v.Length}\"),\n                },\n                uint => v.Length switch\n                {\n                    4 => (object)new UInt4((uint)v[0], (uint)v[1], (uint)v[2], (uint)v[3]),\n                    _ => throw new NotSupportedException($\"Unsupported uint vector size: {v.Length}\"),\n                },\n                _ => throw new NotSupportedException($\"Unsupported constant composite element type: {v[0]?.GetType()}\"),\n            };\n        }\n    }\n}","sourceCodeStart":623,"sourceCodeEnd":659,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/shaders/Stride.Shaders.Compilers/SDSL/ShaderMixer.CBuffers.cs#L623-L659","documentation":"ConvertDefaultValue maps a shader constant's default float vector into a managed Stride vector type, but only sizes 2, 3, and 4 have mappings. Any other component count (e.g. 1, 5, or non-square matrices flattened) hits the switch default and throws NotSupportedException.","triggerScenarios":"A cbuffer member with a default value declared as float1 (or floatN with N outside 2..4) reaching ConvertDefaultValue via ComputeCBufferReflection; matrix defaults encoded as vectors of unexpected length.","commonSituations":"float scalar defaults declared with vector initializer syntax; shader code generators emitting float5+ composites; GLSL/HLSL ported code using vec1-like constructs.","solutions":["Change the default value/member to float2, float3, or float4","Use a plain scalar float instead of a 1-component vector","Split larger composites into supported vector types"],"exampleFix":"// before\nfloat1 Scale = float1(2.0);\n// after\nfloat Scale = 2.0;","handlingStrategy":"validation","validationCode":"if (elemType == \"float\" && composite.Length is < 2 or > 4)\n    throw new ArgumentException(\"float default vectors must have 2-4 components\");","typeGuard":null,"tryCatchPattern":"try { result = mixer.MergeSDSL(tree); }\ncatch (NotSupportedException ex) when (ex.Message.StartsWith(\"Unsupported float vector size\")) {\n    fixDefaultValueType(memberName);\n}","preventionTips":["Use scalars for 1-component defaults","Keep default vectors at 2-4 components","Avoid matrix defaults routed through vector conversion"],"tags":["shaders","sdsl","default-values","vectors"],"backgroundTag":"unsupported-dtype","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"}