stride3d/stride · error · ArgumentOutOfRangeException
Indices for Double2 run from 0 to 1, inclusive.
Error message
Indices for Double2 run from 0 to 1, inclusive.
What it means
The Double2 indexer bounds-checks the index parameter and throws ArgumentOutOfRangeException when the index is not 0 or 1. It is a guard on component access: 0 maps to the X component and 1 to Y, and since Double2 has only two components, any other index (negative or >= 2) is rejected.
Solutions
- Use index 0 (X) or 1 (Y) only.
- Fix loop bounds to i < 2, or use the vector's component count genericly.
- Access .X/.Y properties directly when the component is known.
Example fix
// before for (int i = 0; i < 3; i++) sum += v[i]; // after for (int i = 0; i < 2; i++) sum += v[i];
Defensive patterns
Strategy: validation
Validate before calling
if (index < 0 || index > 1) throw new ArgumentOutOfRangeException(nameof(index)); var c = vector[index];
Type guard
bool IsValidVector2Index(int i) => i is 0 or 1;
Try / catch
try { var c = v[i]; }
catch (ArgumentOutOfRangeException ex) { /* default component or skip */ } Prevention
- Use .X/.Y properties instead of the indexer.
- Bound component loops by the actual vector dimension (2).
- Do not reuse loops written for Double3/Double4 on Double2.
When it happens
Trigger: Reading vector[index] where index < 0 or index > 1, e.g. vector[2] in a loop written for a 3- or 4-component vector type.
Common situations: Generic vector-processing code with a hardcoded component count of 3 or 4 applied to a 2D vector; off-by-one loops (i <= 2); copy-pasted code from Double3/Double4.
Related errors
- Indices for ColorBGRA run from 0 to 3, inclusive.
- There must be two and only two input values for Double2.
- There must be four and only four input values for Double4.
- Indices for Double4 run from 0 to 3, inclusive.
- Indices for Int2 run from 0 to 1, inclusive.
AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14).
Data as JSON: /api/errors/85f3cc9d2a8a6299.
Report an issue: GitHub.
Appendix: source
Thrown at sources/core/Stride.Core.Mathematics/Double2.cs:125
get { return Math.Abs((X * X) + (Y * Y) - 1f) < MathUtil.ZeroTolerance; }
}
/// <summary>
/// Gets or sets the component at the specified index.
/// </summary>
/// <value>The value of the X or Y component, depending on the index.</value>
/// <param name="index">The index of the component to access. Use 0 for the X component and 1 for the Y component.</param>
/// <returns>The value of the component at the specified index.</returns>
/// <exception cref="ArgumentOutOfRangeException">Thrown when the <paramref name="index"/> is out of the range [0, 1].</exception>
public double this[int index]
{
readonly get
{
return index switch
{
0 => X,
1 => Y,
_ => throw new ArgumentOutOfRangeException(nameof(index), "Indices for Double2 run from 0 to 1, inclusive."),
};
}
set
{
switch (index)
{
case 0: X = value; break;
case 1: Y = value; break;
default: throw new ArgumentOutOfRangeException(nameof(index), "Indices for Double2 run from 0 to 1, inclusive.");
}
}
}
/// <summary>
/// Casts from System.Numerics to Stride.Maths vectors
/// </summary>
/// <param name="v">Value to cast</param>View on GitHub (pinned to 96fad776d2)