stride3d/stride · error · ArgumentOutOfRangeException
Indices for UInt4 run from 0 to 3, inclusive.
Error message
Indices for UInt4 run from 0 to 3, inclusive.
What it means
Indexer bounds guard on UInt4 this[index]: the requested component index is outside [0,3]; none of the switch cases matched, so there is no X/Y/Z/W component to return. The faulting input is the index argument to the indexer.
Solutions
- Clamp or validate the index to 0..3 before indexing.
- Fix loop bounds to i < 4 when iterating UInt4 components.
- Use component properties (X, Y, Z, W) directly when the index is known statically.
Example fix
// before for (int i = 0; i < 5; i++) sum += v[i]; // after for (int i = 0; i < 4; i++) sum += v[i];
Defensive patterns
Strategy: validation
Validate before calling
if (index < 0 || index > 3)
throw new ArgumentOutOfRangeException(nameof(index), "UInt4 index must be 0..3.");
var component = v[index]; Type guard
bool IsValidUInt4Index(int i) => i >= 0 && i <= 3;
Try / catch
try
{
component = v[index];
}
catch (ArgumentOutOfRangeException)
{
component = 0; // or rethrow with context about the bad index
} Prevention
- Use compile-time constants or named properties (X/Y/Z/W) instead of runtime indices.
- Bound component loops with the vector's component count (4 for UInt4).
- Never reuse loop bounds from other vector types when indexing.
When it happens
Trigger: Reading v[i] on a UInt4 with i outside 0..3, e.g. looping to i < 5 for a 4-component type, or using a negative index computed from an off-by-one expression.
Common situations: Generic component-copy loops sized from a different vector type; iterating both a Vector4-sized buffer and UInt4 values with a shared loop bound; computed index from bad data.
Related errors
- Indices for Double4 run from 0 to 3, inclusive.
- Indices for Vector2 run from 0 to 1, inclusive.
- Indices for ColorBGRA run from 0 to 3, inclusive.
- Indices for Double3 run from 0 to 2, 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/0613eb133c661701.
Report an issue: GitHub.
Appendix: source
Thrown at sources/core/Stride.Core.Mathematics/UInt4.cs:161
/// <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 uint this[uint index]
{
get
{
switch (index)
{
case 0:
return X;
case 1:
return Y;
case 2:
return Z;
case 3:
return W;
}
throw new ArgumentOutOfRangeException(nameof(index), "Indices for UInt4 run from 0 to 3, inclusive.");
}
set
{
switch (index)
{
case 0:
X = value;
break;
case 1:
Y = value;
break;
case 2:
Z = value;
break;
case 3:
W = value;
break;View on GitHub (pinned to 96fad776d2)