stride3d/stride · error · NotSupportedException
Unsupported float vector size
Error message
Unsupported float vector size: {v.Length} What it means
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.
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
Example fix
// before float1 Scale = float1(2.0); // after float Scale = 2.0;
Defensive patterns
Strategy: validation
Validate before calling
if (elemType == "float" && composite.Length is < 2 or > 4)
throw new ArgumentException("float default vectors must have 2-4 components"); Try / catch
try { result = mixer.MergeSDSL(tree); }
catch (NotSupportedException ex) when (ex.Message.StartsWith("Unsupported float vector size")) {
fixDefaultValueType(memberName);
} Prevention
- Use scalars for 1-component defaults
- Keep default vectors at 2-4 components
- Avoid matrix defaults routed through vector conversion
When it happens
Trigger: 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.
Common situations: float scalar defaults declared with vector initializer syntax; shader code generators emitting float5+ composites; GLSL/HLSL ported code using vec1-like constructs.
Related errors
- Unsupported int vector size
- Unsupported uint vector size
- Unsupported constant composite element type
- Could not find cbuffer member link info for
- [Color] attribute can only be applied on float3/float4…
AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14).
Data as JSON: /api/errors/e7bc0a0a58769043.
Report an issue: GitHub.
Appendix: source
Thrown at sources/shaders/Stride.Shaders.Compilers/SDSL/ShaderMixer.CBuffers.cs:641
/// <summary>
/// Converts compiler-internal <see cref="ConstantVector"/> to serializable CLR types
/// that the engine expects (Vector2/3/4, Int2/3/4, etc.).
/// Scalars (float, int, uint, bool) pass through unchanged.
/// </summary>
private static object? ConvertDefaultValue(object? value)
{
if (value is not ConstantVector cv)
return value;
var v = cv.Values;
return v[0] switch
{
float => v.Length switch
{
2 => new Vector2((float)v[0], (float)v[1]),
3 => new Vector3((float)v[0], (float)v[1], (float)v[2]),
4 => (object)new Vector4((float)v[0], (float)v[1], (float)v[2], (float)v[3]),
_ => throw new NotSupportedException($"Unsupported float vector size: {v.Length}"),
},
int => v.Length switch
{
2 => new Int2((int)v[0], (int)v[1]),
3 => new Int3((int)v[0], (int)v[1], (int)v[2]),
4 => (object)new Int4((int)v[0], (int)v[1], (int)v[2], (int)v[3]),
_ => throw new NotSupportedException($"Unsupported int vector size: {v.Length}"),
},
uint => v.Length switch
{
4 => (object)new UInt4((uint)v[0], (uint)v[1], (uint)v[2], (uint)v[3]),
_ => throw new NotSupportedException($"Unsupported uint vector size: {v.Length}"),
},
_ => throw new NotSupportedException($"Unsupported constant composite element type: {v[0]?.GetType()}"),
};
}
}
}View on GitHub (pinned to 96fad776d2)