stride3d/stride · error · ArgumentOutOfRangeException

Indices for Int3 run from 0 to 2, inclusive.

Error message

Indices for Int3 run from 0 to 2, inclusive.

What it means

The Int3 indexer bounds-checks the index parameter and throws ArgumentOutOfRangeException when the index is outside [0, 2]. It is a generic guard on component access: 0 selects X, 1 Y, 2 Z; Int3 has exactly three components, so any other index is invalid.

Solutions

  1. Bound loops to i < 3 for Int3
  2. Validate the index: if ((uint)index < 3) before access
  3. Parameterize the component count by vector type instead of hardcoding

Example fix

// before
for (int i = 0; i < 4; i++) sum += v[i]; // throws at i=3
// after
for (int i = 0; i < 3; i++) sum += v[i];
Defensive patterns

Strategy: validation

Validate before calling

if (index is < 0 or > 2)
    throw new ArgumentOutOfRangeException(nameof(index));
var component = v[index];

Type guard

static bool IsValidInt3Index(int i) => (uint)i < 3;

Try / catch

try { component = v[index]; }
catch (ArgumentOutOfRangeException ex) when (ex.ParamName == "index")
{
    component = 0; // or propagate a data error
}

Prevention

When it happens

Trigger: Reading v[index] with index outside 0..2, e.g. a loop bounded by 4 (copied from Int4 code) or an index taken from external metadata.

Common situations: Generic vector math helpers reused across Int2/Int3/Int4 with a shared hardcode bound; data-driven shader/attribute component lookups.

Related errors


AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14). Data as JSON: /api/errors/bd63a23c8f07c12f. Report an issue: GitHub.

Appendix: source

Thrown at sources/core/Stride.Core.Mathematics/Int3.cs:161

    }

    /// <summary>
    /// Gets or sets the component at the specified index.
    /// </summary>
    /// <value>The value of the X, Y, or Z component, depending on the index.</value>
    /// <param name="index">The index of the component to access. Use 0 for the X component, 1 for the Y component, and 2 for the Z 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, 2].</exception>
    public int this[int index]
    {
        readonly get
        {
            return index switch
            {
                0 => X,
                1 => Y,
                2 => Z,
                _ => throw new ArgumentOutOfRangeException(nameof(index), "Indices for Int3 run from 0 to 2, inclusive."),
            };
        }

        set
        {
            switch (index)
            {
                case 0: X = value; break;
                case 1: Y = value; break;
                case 2: Z = value; break;
                default: throw new ArgumentOutOfRangeException(nameof(index), "Indices for Int3 run from 0 to 2, inclusive.");
            }
        }
    }

    /// <summary>
    /// Casts from System.Numerics to Stride.Maths vectors
    /// </summary>

View on GitHub (pinned to 96fad776d2)