{"record":{"id":"f22ac0f89abce208","repo":"stride3d/stride","slug":"indices-for-vector3-run-from-0-to-2-inclusive","errorCode":null,"errorMessage":"Indices for Vector3 run from 0 to 2, inclusive.","messagePattern":"Indices for Vector3 run from 0 to 2, inclusive\\.","errorType":"exception","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"sources/core/Stride.Core.Mathematics/Vector3.cs","lineNumber":172,"sourceCode":"    /// <summary>\n    /// Gets or sets the component at the specified index.\n    /// </summary>\n    /// <value>The value of the X, Y, or Z component, depending on the index.</value>\n    /// <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>\n    /// <returns>The value of the component at the specified index.</returns>\n    /// <exception cref=\"System.ArgumentOutOfRangeException\">Thrown when the <paramref name=\"index\"/> is out of the range [0, 2].</exception>\n    public float this[int index]\n    {\n        get\n        {\n            switch (index)\n            {\n                case 0: return X;\n                case 1: return Y;\n                case 2: return Z;\n            }\n\n            throw new ArgumentOutOfRangeException(nameof(index), \"Indices for Vector3 run from 0 to 2, inclusive.\");\n        }\n\n        set\n        {\n            switch (index)\n            {\n                case 0: X = value; break;\n                case 1: Y = value; break;\n                case 2: Z = value; break;\n                default: throw new ArgumentOutOfRangeException(nameof(index), \"Indices for Vector3 run from 0 to 2, inclusive.\");\n            }\n        }\n    }\n\n    /// <summary>\n    /// Casts from System.Numerics to Stride.Maths vectors\n    /// </summary>\n    /// <param name=\"v\">Value to cast</param>","sourceCodeStart":154,"sourceCodeEnd":190,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/core/Stride.Core.Mathematics/Vector3.cs#L154-L190","documentation":"Thrown by the Vector3 indexer getter when the index is outside 0..2. The indexer switches on index and returns X, Y, or Z; any other value falls through to ArgumentOutOfRangeException. Vector3 has exactly three components.","triggerScenarios":"Accessing vector[index] with index < 0 or index > 2, commonly in loops with a wrong bound (e.g. iterating to vector.Length or 4 for SIMD-sized arrays) or passing a component index computed from data.","commonSituations":"Generic component-wise loops written for Vector4 reused on Vector3; component index read from config; off-by-one loop conditions.","solutions":["Clamp or validate the index to 0..2 before accessing the indexer","Fix loop bounds to iterate i < 3 for Vector3","Use a Count/ComponentCount constant instead of a hardcoded 4"],"exampleFix":"// before\nfor (int i = 0; i < 4; i++) sum += v[i];\n// after\nfor (int i = 0; i < 3; i++) sum += v[i];","handlingStrategy":"validation","validationCode":"if (index < 0 || index > 2) throw new ArgumentOutOfRangeException(nameof(index));","typeGuard":"static bool IsValidComponentIndex(int index) => (uint)index <= 2u;","tryCatchPattern":"try { var c = v[index]; }\ncatch (ArgumentOutOfRangeException) { /* clamp or handle invalid component index */ }","preventionTips":["Bound component loops with 3 (or a Vector3 component-count constant)","Do not reuse Vector4-sized loops for Vector3","Validate data-driven component indexes"],"tags":["csharp","index-out-of-range","vector-math"],"backgroundTag":"index-out-of-range","analyzedSha":"96fad776d210c221682aac1ccdf4c79dc046fc38","analyzedAt":"2026-09-14T02:59:31.279Z","contentChangedAt":"2026-09-14T02:59:31.279Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}