stride3d/stride · error · NotSupportedException

Unsupported constant composite element type

Error message

Unsupported constant composite element type: {v[0]?.GetType()}

What it means

ConvertDefaultValue switches on the element type of the constant composite (float, int, uint). A default value whose element type is none of these — e.g. bool, double, or a nested composite — has no conversion and throws NotSupportedException reporting the runtime element type.

Solutions

  1. Change the default to a float, int, or uint vector type
  2. Encode bool flags as int vectors (0/1)
  3. Remove the default value or express it via a supported type

Example fix

// before
bool2 Enabled = bool2(true, false);
// after
int2 Enabled = int2(1, 0);
Defensive patterns

Strategy: validation

Validate before calling

if (elemType is not ("float" or "int" or "uint"))
    throw new ArgumentException($"Unsupported default element type: {elemType}");

Type guard

bool IsSupportedDefaultType(TypeDescription t) =>
    t is ScalarType { Type: Scalar.Float or Scalar.Int or Scalar.UInt };

Try / catch

try { result = mixer.MergeSDSL(tree); }
catch (NotSupportedException ex) when (ex.Message.Contains("Unsupported constant composite element type")) {
    convertBoolDefaultToInt(memberName);
}

Prevention

When it happens

Trigger: A cbuffer member default of type bool2/bool3/bool4, double vector, or a nested/struct composite passed to ConvertDefaultValue via ComputeCBufferReflection.

Common situations: bool vector flags (bvec from GLSL) used as defaults; double-precision literals in shader defaults; defaults assigned from struct-typed constants.

Related errors


AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14). Data as JSON: /api/errors/a75e032cbaa789f4. Report an issue: GitHub.

Appendix: source

Thrown at sources/shaders/Stride.Shaders.Compilers/SDSL/ShaderMixer.CBuffers.cs:655

                {
                    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)