{"record":{"id":"bd63a23c8f07c12f","repo":"stride3d/stride","slug":"indices-for-int3-run-from-0-to-2-inclusive","errorCode":null,"errorMessage":"Indices for Int3 run from 0 to 2, inclusive.","messagePattern":"Indices for Int3 run from 0 to 2, inclusive\\.","errorType":"exception","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"sources/core/Stride.Core.Mathematics/Int3.cs","lineNumber":161,"sourceCode":"    }\n\n    /// <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=\"ArgumentOutOfRangeException\">Thrown when the <paramref name=\"index\"/> is out of the range [0, 2].</exception>\n    public int this[int index]\n    {\n        readonly get\n        {\n            return index switch\n            {\n                0 => X,\n                1 => Y,\n                2 => Z,\n                _ => throw new ArgumentOutOfRangeException(nameof(index), \"Indices for Int3 run from 0 to 2, inclusive.\"),\n            };\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 Int3 run from 0 to 2, inclusive.\");\n            }\n        }\n    }\n\n    /// <summary>\n    /// Casts from System.Numerics to Stride.Maths vectors\n    /// </summary>","sourceCodeStart":143,"sourceCodeEnd":179,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/core/Stride.Core.Mathematics/Int3.cs#L143-L179","documentation":"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.","triggerScenarios":"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.","commonSituations":"Generic vector math helpers reused across Int2/Int3/Int4 with a shared hardcode bound; data-driven shader/attribute component lookups.","solutions":["Bound loops to i < 3 for Int3","Validate the index: if ((uint)index < 3) before access","Parameterize the component count by vector type instead of hardcoding"],"exampleFix":"// before\nfor (int i = 0; i < 4; i++) sum += v[i]; // throws at i=3\n// after\nfor (int i = 0; i < 3; i++) sum += v[i];","handlingStrategy":"validation","validationCode":"if (index is < 0 or > 2)\n    throw new ArgumentOutOfRangeException(nameof(index));\nvar component = v[index];","typeGuard":"static bool IsValidInt3Index(int i) => (uint)i < 3;","tryCatchPattern":"try { component = v[index]; }\ncatch (ArgumentOutOfRangeException ex) when (ex.ParamName == \"index\")\n{\n    component = 0; // or propagate a data error\n}","preventionTips":["Bound loops to 3 for Int3","Parameterize component counts by vector type in generic code","Use X/Y/Z properties when the component is static"],"tags":["csharp","stride","mathematics","indexer","argument-out-of-range"],"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-15T23:17:13.987Z"}