stride3d/stride · error · ArgumentOutOfRangeException

Value must be in between 1 and 32

Error message

Value must be in between 1 and 32

What it means

ControlPointCount converts a base PrimitiveType into a PatchList primitive type with the given number of control points. The library throws ArgumentOutOfRangeException because tessellation patches only support between 1 and 32 control points; anything outside that range cannot be mapped onto a valid primitive type enum value.

Solutions

  1. Pass a control-point count between 1 and 32 (inclusive), matching the count declared in your hull/domain shader
  2. Clamp or validate the value before calling: Math.Clamp(controlPoints, 1, 32)
  3. Check the source asset/shader for an incorrect control point count value

Example fix

// before
var type = ControlPointCount(PrimitiveType.PatchList, 40);
// after
var type = ControlPointCount(PrimitiveType.PatchList, Math.Clamp(controlPoints, 1, 32));
Defensive patterns

Strategy: validation

Validate before calling

if (controlPoints < 1 || controlPoints > 32) throw new ArgumentOutOfRangeException(nameof(controlPoints));

Try / catch

try { type = ControlPointCount(PrimitiveType.PatchList, n); } catch (ArgumentOutOfRangeException) { type = PrimitiveType.TriangleList; }

Prevention

When it happens

Trigger: Calling ControlPointCount with controlPoints < 1 or > 32, e.g. ControlPointCount(PrimitiveType.PatchList, 0) or 33.

Common situations: Configuring tessellation in rendering pipelines where the patch control-point count comes from a user-supplied asset or shader constant that was not clamped; off-by-one errors using 33 instead of 32.

Understand the failure class

Background: "value must be between 0 and 1" / "out of range" / "must not be negative" errors: fixing range-validation failures across open-source libraries — this error's family across 42 libraries.

Related errors


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

Appendix: source

Thrown at sources/engine/Stride.Graphics/PrimitiveTypeExtensions.cs:31

    /// <summary>
    ///   Interpret the input vertex data type as a <strong>patch list</strong> for tesselation with a
    ///   specific number of <strong>control points</strong>.
    /// </summary>
    /// <param name="controlPoints">The number of control points. It must be a value in the range 1 to 32, inclusive.</param>
    /// <returns>
    ///   A <see cref="PrimitiveType"/> value that represents a patch list with the specified number of control points.
    /// </returns>
    /// <exception cref="ArgumentException">Control points apply only to <see cref="PrimitiveType.PatchList"/>.</exception>
    /// <exception cref="ArgumentOutOfRangeException"><paramref name="controlPoints"/> must be in the range 1 to 32, inclusive.</exception>"
    public static PrimitiveType ControlPointCount(this PrimitiveType primitiveType, int controlPoints)
    {
        if (primitiveType != PrimitiveType.PatchList)
            throw new ArgumentException($"Control points apply only to {nameof(PrimitiveType)}.{nameof(PrimitiveType.PatchList)}", nameof(primitiveType));

        const int MIN_CONTROL_POINTS = 1, MAX_CONTROL_POINTS = 32;

        if (controlPoints < MIN_CONTROL_POINTS || controlPoints > MAX_CONTROL_POINTS)
            throw new ArgumentOutOfRangeException(nameof(controlPoints), $"Value must be in between {MIN_CONTROL_POINTS} and {MAX_CONTROL_POINTS}");

        return PrimitiveType.PatchList + controlPoints - 1;
    }
}

View on GitHub (pinned to 96fad776d2)