stride3d/stride · error · ArgumentOutOfRangeException
There must be three and only three input values for Half3.
Error message
There must be three and only three input values for Half3.
What it means
Thrown by the Half3(Half[]) constructor when the input array does not contain exactly three elements. Half3 is a fixed-size 3-component vector (X, Y, Z), so it can only be built from exactly three Half values. Thrown as ArgumentOutOfRangeException for the 'values' parameter.
Solutions
- Ensure the array has exactly 3 elements before constructing
- Slice the exact three components out of a larger packed buffer
- Use Half2 or Half4 for data that genuinely has 2 or 4 components
Example fix
// before
var n = new Half3(halfs); // halfs.Length == 4 -> throws
// after
var n = new Half3(new[] { halfs[0], halfs[1], halfs[2] }); Defensive patterns
Strategy: validation
Validate before calling
if (values is null) throw new ArgumentNullException(nameof(values));
if (values.Length != 3) throw new ArgumentException($"Half3 requires exactly 3 values, got {values.Length}.", nameof(values)); Type guard
static bool IsValidHalf3Source(Half[]? values) => values is { Length: 3 }; Try / catch
try { var v = new Half3(values); }
catch (ArgumentOutOfRangeException ex) when (ex.ParamName == "values")
{
// handle malformed attribute data
var v = new Half3(Half.Zero, Half.Zero, Half.Zero);
} Prevention
- Validate array length is exactly 3 before constructing
- Slice exactly three components out of packed/interleaved buffers
- Use Half2/Half4 for data with a different component count
When it happens
Trigger: Calling new Half3(Half[]) with an array of length 0, 1, 2, or 4+ — e.g. passing a Half2 array or a Half4 array without slicing.
Common situations: Mesh vertex data where positions sometimes carry a W or padding component; packed half-float attribute streams with miscomputed offsets; mixing 2D and 3D attribute data paths.
Related errors
- There must be two and only two input values for Half2.
- There must be four and only four input values for Half4.
- There must be four and only four input values for Double4.
- There must be two and only two input values for Double2.
- There must be three and only three input values for Double3.
AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14).
Data as JSON: /api/errors/b6ea29ec0b3a8c0d.
Report an issue: GitHub.
Appendix: source
Thrown at sources/core/Stride.Core.Mathematics/Half3.cs:120
/// <param name="value">The value to set for the X, Y, and Z components.</param>
public Half3(Half value)
{
X = value;
Y = value;
Z = value;
}
/// <summary>
/// Initializes a new instance of the <see cref="Half3"/> struct.
/// </summary>
/// <param name="values">The values to assign to the X, Y, and Z components of the vector. This must be an array with three elements.</param>
/// <exception cref="ArgumentNullException">Thrown when <paramref name="values"/> is <c>null</c>.</exception>
/// <exception cref="ArgumentOutOfRangeException">Thrown when <paramref name="values"/> contains more or less than three elements.</exception>
public Half3(Half[] values)
{
ArgumentNullException.ThrowIfNull(values);
if (values.Length != 3)
throw new ArgumentOutOfRangeException(nameof(values), "There must be three and only three input values for Half3.");
X = values[0];
Y = values[1];
Z = values[2];
}
/// <summary>
/// Initializes a new instance of the <see cref="Half3"/> structure.
/// </summary>
/// <param name="x">The X component.</param>
/// <param name="y">The Y component.</param>
/// <param name="z">The Z component.</param>
public Half3(float x, float y, float z)
{
X = (Half)x;
Y = (Half)y;
Z = (Half)z;
}View on GitHub (pinned to 96fad776d2)