stride3d/stride · error · ArgumentOutOfRangeException
There must be four and only four input values for Double4.
Error message
There must be four and only four input values for Double4.
What it means
Thrown by the Double4(double[]) constructor when the input array does not contain exactly four elements. Double4 is a fixed-size 4-component vector (X, Y, Z, W), so it can only be built from exactly four doubles. The library throws ArgumentOutOfRangeException naming the 'values' parameter to fail fast instead of silently padding or truncating.
Solutions
- Ensure the array passed to the constructor has exactly 4 elements before constructing
- If data has fewer components, add the missing one explicitly (e.g. W = 0 or 1) before constructing
- Use a 3-component type (Double3) if the data is genuinely 3D instead of padding into Double4
- Log the actual values.Length to identify where the malformed array originates
Example fix
// before
var v = new Double4(values); // values.Length == 3 -> throws
// after
if (values.Length != 4)
throw new ArgumentException($"Expected 4 values, got {values.Length}", nameof(values));
var v = new Double4(values); Defensive patterns
Strategy: validation
Validate before calling
if (values is null) throw new ArgumentNullException(nameof(values));
if (values.Length != 4) throw new ArgumentException($"Double4 requires exactly 4 values, got {values.Length}.", nameof(values)); Type guard
static bool IsValidDouble4Source(double[]? values) => values is { Length: 4 }; Try / catch
try { var v = new Double4(values); }
catch (ArgumentOutOfRangeException ex) when (ex.ParamName == "values")
{
// fall back to default vector or report malformed input
var v = Double4.Zero;
} Prevention
- Validate array length with a pattern check (values is { Length: 4 }) before constructing
- Centralize vector construction in a helper that pads/truncates data deliberately
- Prefer strongly-typed component constructors (new Double4(x, y, z, w)) over array constructors
- Assert lengths at deserialization boundaries where vector data enters the system
When it happens
Trigger: Calling new Double4(double[]) with an array whose Length is not 4 — e.g. an empty array, a 3-element array missing W, or a 5-element array from parsing a longer data file.
Common situations: Loading vector data from files or network payloads where a record has fewer/more fields than expected; slicing a larger buffer with wrong start/end indices; converting from 3D data (xyz) to 4D (xyzw) and forgetting the W component.
Related errors
- There must be two and only two input values for Double2.
- There must be two and only two input values for Half2.
- There must be three and only three input values for Half3.
- There must be four and only four input values for Half4.
- There must be three and only three input values for Color3.
AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14).
Data as JSON: /api/errors/0dabcc6c7f592a0f.
Report an issue: GitHub.
Appendix: source
Thrown at sources/core/Stride.Core.Mathematics/Double4.cs:141
public Double4(Double2 value, double z, double w)
{
X = value.X;
Y = value.Y;
Z = z;
W = w;
}
/// <summary>
/// Initializes a new instance of the <see cref="Double4"/> struct.
/// </summary>
/// <param name="values">The values to assign to the X, Y, Z, and W components of the vector. This must be an array with four 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 four elements.</exception>
public Double4(double[] values)
{
ArgumentNullException.ThrowIfNull(values);
if (values.Length != 4)
throw new ArgumentOutOfRangeException(nameof(values), "There must be four and only four input values for Double4.");
X = values[0];
Y = values[1];
Z = values[2];
W = values[3];
}
/// <summary>
/// Initializes a new instance of the <see cref="Double4"/> struct.
/// </summary>
/// <param name="v">The Vector4 to construct the Double4 from.</param>
public Double4(Vector4 v)
{
X = v.X;
Y = v.Y;
Z = v.Z;
W = v.W;
}View on GitHub (pinned to 96fad776d2)