{"record":{"id":"83a804b809649c39","repo":"stride3d/stride","slug":"indices-for-double4-run-from-0-to-3-inclusive","errorCode":null,"errorMessage":"Indices for Double4 run from 0 to 3, inclusive.","messagePattern":"Indices for Double4 run from 0 to 3, inclusive\\.","errorType":"exception","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"sources/core/Stride.Core.Mathematics/Double4.cs","lineNumber":186,"sourceCode":"\n    /// <summary>\n    /// Gets or sets the component at the specified index.\n    /// </summary>\n    /// <value>The value of the X, Y, Z, or W 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, 2 for the Z component, and 3 for the W 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, 3].</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                3 => W,\n                _ => throw new ArgumentOutOfRangeException(nameof(index), \"Indices for Double4 run from 0 to 3, 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                case 3: W = value; break;\n                default: throw new ArgumentOutOfRangeException(nameof(index), \"Indices for Double4 run from 0 to 3, inclusive.\");\n            }\n        }\n    }\n\n    /// <summary>\n    /// Casts from System.Numerics to Stride.Maths vectors","sourceCodeStart":168,"sourceCodeEnd":204,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/core/Stride.Core.Mathematics/Double4.cs#L168-L204","documentation":"Thrown by the Double4 indexer's getter when the index is outside 0..3. Double4 has exactly four components (0=X, 1=Y, 2=Z, 3=W); any other index is invalid. Thrown as ArgumentOutOfRangeException for the 'index' parameter.","triggerScenarios":"Calling d4[i] (get) with i < 0 or i > 3, typically from a loop with a wrong bound (e.g. i <= 4) or an index taken from unvalidated external data.","commonSituations":"Generic 'copy N components' loops with off-by-one bounds; mapping external component IDs or channel numbers directly to vector indices; iterating to Length of a differently-sized array.","solutions":["Clamp or validate the index to 0..3 before indexing","Fix loop bounds to use 'i < 4' or a component-count constant of 4","If the component count varies, use the array-backed path instead of fixed-size Double4 indexing"],"exampleFix":"// before\nfor (int i = 0; i <= 4; i++) sum += d4[i]; // i==4 throws\n// after\nfor (int i = 0; i < 4; i++) sum += d4[i];","handlingStrategy":"validation","validationCode":"if (index < 0 || index > 3) throw new ArgumentOutOfRangeException(nameof(index));","typeGuard":"static bool IsValidComponentIndex(int i) => i is >= 0 and <= 3;","tryCatchPattern":"try { var c = d4[index]; }\ncatch (ArgumentOutOfRangeException ex) when (ex.ParamName == \"index\")\n{\n    // handle invalid component index\n}","preventionTips":["Use constants or an enum (X=0, Y=1, Z=2, W=3) instead of magic numbers for indices","Bound loops with '< 4' or Double4.ComponentCount","Never feed raw external channel IDs directly into vector indexers"],"tags":["index-out-of-range","mathematics","vector","indexer","csharp"],"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"}