stride3d/stride · error · ArgumentOutOfRangeException
There must be four and only four input values for Plane.
Error message
There must be four and only four input values for Plane.
What it means
Plane's float[] constructor requires the array to hold exactly 4 elements: Normal.X, Normal.Y, Normal.Z and D. The library throws ArgumentOutOfRangeException when the array length differs from 4, because a plane in 3D cannot be described by any other number of coefficients. This fail-fast check prevents silent misinterpretation of the input array.
Solutions
- Ensure the array passed to the Plane(float[]) constructor contains exactly 4 floats (Nx, Ny, Nz, D)
- Check values.Length == 4 before constructing, or resize/slice the array
- Verify the data source (file/config/network) actually provides 4 coefficients per plane
Example fix
// before
var plane = new Plane(normalComponents); // float[3]
// after
var values = new float[] { n.X, n.Y, n.Z, d };
if (values.Length == 4) { var plane = new Plane(values); } Defensive patterns
Strategy: validation
Validate before calling
if (values == null || values.Length != 4) throw new ArgumentException("Plane requires exactly 4 floats: Nx, Ny, Nz, D");
var plane = new Plane(values); Type guard
bool IsValidPlaneArray(float[] v) => v != null && v.Length == 4;
Try / catch
try { var plane = new Plane(values); }
catch (ArgumentOutOfRangeException ex) { /* ex.ParamName == "values"; handle bad array length */ } Prevention
- Always build plane arrays from explicit (Nx, Ny, Nz, D) sources
- Assert array length 4 in deserialization code before constructing
- Prefer the component constructor over the array constructor
When it happens
Trigger: Calling new Plane(float[] values) with an array whose Length is not exactly 4, e.g. passing only the 3 normal components, or passing an extra element.
Common situations: Deserializing plane data from config or files where the array was truncated or extended; converting from another library's plane representation that uses 3 or 5 values; off-by-one slicing of a larger float buffer.
Related errors
- Indices for ColorBGRA run from 0 to 3, inclusive.
- There must be three and only three input values for Double3.
- The destination array must be of same length or larger…
- There must be four and only four input values for Double4.
- The destination array must be of same length or larger…
AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14).
Data as JSON: /api/errors/873536ed88869763.
Report an issue: GitHub.
Appendix: source
Thrown at sources/core/Stride.Core.Mathematics/Plane.cs:135
Normal.X = yz * invPyth;
Normal.Y = xz * invPyth;
Normal.Z = xy * invPyth;
D = -((Normal.X * point1.X) + (Normal.Y * point1.Y) + (Normal.Z * point1.Z));
}
/// <summary>
/// Initializes a new instance of the <see cref="Stride.Core.Mathematics.Plane"/> struct.
/// </summary>
/// <param name="values">The values to assign to the A, B, C, and D components of the plane. 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 Plane(float[] values)
{
if (values == null)
throw new ArgumentNullException(nameof(values));
if (values.Length != 4)
throw new ArgumentOutOfRangeException(nameof(values), "There must be four and only four input values for Plane.");
Normal.X = values[0];
Normal.Y = values[1];
Normal.Z = values[2];
D = values[3];
}
/// <summary>
/// Gets or sets the component at the specified index.
/// </summary>
/// <value>The value of the A, B, C, or D component, depending on the index.</value>
/// <param name="index">The index of the component to access. Use 0 for the A component, 1 for the B component, 2 for the C component, and 3 for the D component.</param>
/// <returns>The value of the component at the specified index.</returns>
/// <exception cref="System.ArgumentOutOfRangeException">Thrown when the <paramref name="index"/> is out of the range [0, 3].</exception>
public float this[int index]
{
get
{View on GitHub (pinned to 96fad776d2)