stride3d/stride · error · ArgumentOutOfRangeException

Indices for Plane run from 0 to 3, inclusive.

Error message

Indices for Plane run from 0 to 3, inclusive.

What it means

The Plane indexer getter only supports indices 0..3, mapping to Normal.X, Normal.Y, Normal.Z and D. Any index outside that range falls through the switch and throws ArgumentOutOfRangeException. This enforces the fixed 4-coefficient layout of a plane.

Solutions

  1. Clamp or validate the index to 0..3 before accessing plane[index]
  2. Fix the loop bound to use the plane coefficient count (4)
  3. For component-wise access, use the named properties Normal and D instead of the indexer

Example fix

// before
for (int i = 0; i <= 4; i++) Console.WriteLine(plane[i]);
// after
for (int i = 0; i < 4; i++) Console.WriteLine(plane[i]);
Defensive patterns

Strategy: validation

Validate before calling

if (index >= 0 && index <= 3) { var c = plane[index]; }

Type guard

bool IsValidPlaneIndex(int i) => (uint)i <= 3u;

Try / catch

try { var c = plane[index]; }
catch (ArgumentOutOfRangeException ex) { /* ex.ParamName == "index"; fall back to default component */ }

Prevention

When it happens

Trigger: Reading plane[idx] where idx < 0 or idx > 3, typically from a loop with a wrong bound (e.g. iterating to plane.Length or 5) or a variable index computed elsewhere.

Common situations: Generic component-access loops written for vectors of other sizes reused on Plane; off-by-one loop conditions; dynamic indices from parsed data.

Related errors


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

Appendix: source

Thrown at sources/core/Stride.Core.Mathematics/Plane.cs:162

    /// 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
        {
            switch (index)
            {
                case 0: return Normal.X;
                case 1: return Normal.Y;
                case 2: return Normal.Z;
                case 3: return D;
            }

            throw new ArgumentOutOfRangeException(nameof(index), "Indices for Plane run from 0 to 3, inclusive.");
        }

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

    /// <summary>
    /// Negates a plane by negating all its coefficients, which result in a plane in opposite direction.
    /// </summary>

View on GitHub (pinned to 96fad776d2)