{"record":{"id":"e4ddd5da85292c6a","repo":"egametang/ET","slug":"vector2f-index-out-of-range","errorCode":null,"errorMessage":"vector2f index out of range","messagePattern":"vector2f index out of range","errorType":"exception","errorClass":"IndexOutOfRangeException","httpStatus":null,"severity":"error","filePath":"Packages/cn.etetet.recast/Scripts/Core/Share/Core/RcVec2f.cs","lineNumber":22,"sourceCode":"namespace DotRecast.Core\n{\n    public struct RcVec2f\n    {\n        public float x;\n        public float y;\n\n        public static RcVec2f Zero { get; } = new RcVec2f { x = 0, y = 0 };\n\n        [MethodImpl(MethodImplOptions.AggressiveInlining)]\n        public float Get(int idx)\n        {\n            if (0 == idx)\n                return x;\n\n            if (1 == idx)\n                return y;\n\n            throw new IndexOutOfRangeException(\"vector2f index out of range\");\n        }\n\n        public override bool Equals(object obj)\n        {\n            if (!(obj is RcVec2f))\n                return false;\n\n            return Equals((RcVec2f)obj);\n        }\n\n        [MethodImpl(MethodImplOptions.AggressiveInlining)]\n        public bool Equals(RcVec2f other)\n        {\n            return x.Equals(other.x) &&\n                   y.Equals(other.y);\n        }\n\n        [MethodImpl(MethodImplOptions.AggressiveInlining)]","sourceCodeStart":4,"sourceCodeEnd":40,"githubUrl":"https://github.com/egametang/ET/blob/5cab01f7a8bee5f49f4781eebe9e2b1c6d7ebe0f/Packages/cn.etetet.recast/Scripts/Core/Share/Core/RcVec2f.cs#L4-L40","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Ensure the index is 0 or 1; if 3D access is needed, use RcVec3f instead.","Add a range check before calling Get and clamp or reject out-of-range indices.","Audit the caller's index source for off-by-one or 3D-assumption bugs."],"exampleFix":"// before\nfloat v = vec2f.Get(axis);\n\n// after\nfloat v = (axis < 0 || axis > 1) ? throw new ArgumentOutOfRangeException(nameof(axis)) : vec2f.Get(axis);","handlingStrategy":"validation","validationCode":"if (idx < 0 || idx > 1) throw new ArgumentOutOfRangeException(nameof(idx));\nreturn vec.Get(idx);","typeGuard":"static bool IsValidVec2Index(int idx) => idx == 0 || idx == 1;","tryCatchPattern":null,"preventionTips":["Range-check indices before calling Get.","Use RcVec3f if 3-component access is needed.","Audit ported code that assumes 3D indices."],"tags":["recast","math","vector","bounds"],"backgroundTag":null,"analyzedSha":"5cab01f7a8bee5f49f4781eebe9e2b1c6d7ebe0f","analyzedAt":"2026-08-13T21:10:40.377Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}