egametang/ET · error · IndexOutOfRangeException

vector2f index out of range

Error message

vector2f index out of range

What it means

RcVec2f.Get(idx) returns x for idx 0 and y for idx 1; any other index throws IndexOutOfRangeException. This is a bounds guard for index-based vector access used in ported Detour math code that sometimes indexes components generically.

Source

Thrown at Packages/cn.etetet.recast/Scripts/Core/Share/Core/RcVec2f.cs:22

namespace DotRecast.Core
{
    public struct RcVec2f
    {
        public float x;
        public float y;

        public static RcVec2f Zero { get; } = new RcVec2f { x = 0, y = 0 };

        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public float Get(int idx)
        {
            if (0 == idx)
                return x;

            if (1 == idx)
                return y;

            throw new IndexOutOfRangeException("vector2f index out of range");
        }

        public override bool Equals(object obj)
        {
            if (!(obj is RcVec2f))
                return false;

            return Equals((RcVec2f)obj);
        }

        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public bool Equals(RcVec2f other)
        {
            return x.Equals(other.x) &&
                   y.Equals(other.y);
        }

        [MethodImpl(MethodImplOptions.AggressiveInlining)]

View on GitHub (pinned to 5cab01f7a8)

Solutions

  1. Ensure the index is 0 or 1; if 3D access is needed, use RcVec3f instead.
  2. Add a range check before calling Get and clamp or reject out-of-range indices.
  3. Audit the caller's index source for off-by-one or 3D-assumption bugs.

Example fix

// before
float v = vec2f.Get(axis);

// after
float v = (axis < 0 || axis > 1) ? throw new ArgumentOutOfRangeException(nameof(axis)) : vec2f.Get(axis);
Defensive patterns

Strategy: validation

Validate before calling

if (idx < 0 || idx > 1) throw new ArgumentOutOfRangeException(nameof(idx));
return vec.Get(idx);

Type guard

static bool IsValidVec2Index(int idx) => idx == 0 || idx == 1;

Prevention

When it happens

Trigger: Calling vec.Get(2) or vec.Get(-1); a loop or array-index computation that produces an index outside [0,1] for a 2-component vector.

Common situations: Code ported from a 3D vector context (expecting idx 0,1,2) applied to a 2D vector; an off-by-one in a loop bound; deserialized data feeding an unexpected index.

Related errors


AI-assisted analysis of egametang/ET@5cab01f7a8 (2026-08-13). Data as JSON: /api/errors/e4ddd5da85292c6a. Report an issue: GitHub.