{"record":{"id":"9f6c322ea74f4f8c","repo":"stride3d/stride","slug":"indices-for-double3-run-from-0-to-2-inclusive","errorCode":null,"errorMessage":"Indices for Double3 run from 0 to 2, inclusive.","messagePattern":"Indices for Double3 run from 0 to 2, inclusive\\.","errorType":"exception","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"sources/core/Stride.Core.Mathematics/Double3.cs","lineNumber":154,"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=\"System.ArgumentOutOfRangeException\">Thrown when the <paramref name=\"index\"/> is out of the range [0, 2].</exception>\n    public double 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 Double3 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 Double3 run from 0 to 2, inclusive.\");\n            }\n        }\n    }\n\n    /// <summary>\n    /// Casts from System.Numerics to Stride.Maths vectors\n    /// </summary>","sourceCodeStart":136,"sourceCodeEnd":172,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/core/Stride.Core.Mathematics/Double3.cs#L136-L172","documentation":"Double3's read-only indexer maps index 0->X, 1->Y, 2->Z and throws ArgumentOutOfRangeException for any other index. This surfaces when iterating the vector with a wrong bound or using an off-by-one loop limit.","triggerScenarios":"Reading v[index] with index < 0 or index > 2, e.g. 'for (int i = 0; i <= 3; i++) v[i]' or indexing with an enum/variable that holds an invalid value.","commonSituations":"Generic per-component loops written for 4-component types (Double4) reused on Double3; serializing components with a hardcoded component count of 4.","solutions":["Loop with 'for (int i = 0; i < 3; i++)' when iterating Double3 components","Access X, Y, Z fields directly instead of the indexer when the component is known at compile time","If the component count varies, check the vector type/dimension before looping"],"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 < 3) { var c = v[index]; } else { /* handle invalid index */ }","typeGuard":"static bool IsValidComponentIndex(int i) => i is >= 0 and <= 2;","tryCatchPattern":"try { var c = v[index]; }\ncatch (ArgumentOutOfRangeException ex) when (ex.ParamName == \"index\") { /* clamp index or log bad accessor */ }","preventionTips":["Iterate with 'i < 3' loops for Double3, not a hardcoded 4","Use .X/.Y/.Z fields when the component is known statically","Centralize dynamic component access in one bounds-checked helper"],"tags":["index-out-of-range","mathematics","double3"],"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"}