{"record":{"id":"227ee4f2fa20e528","repo":"stride3d/stride","slug":"indices-for-color3-run-from-0-to-2-inclusive","errorCode":null,"errorMessage":"Indices for Color3 run from 0 to 2, inclusive.","messagePattern":"Indices for Color3 run from 0 to 2, inclusive\\.","errorType":"exception","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"sources/core/Stride.Core.Mathematics/Color3.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 red, green, or blue component, depending on the index.</value>\n    /// <param name=\"index\">The index of the component to access. Use 0 for the red component, 1 for the green component, and 2 for the blue 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        readonly get\n        {\n            return index switch\n            {\n                0 => R,\n                1 => G,\n                2 => B,\n                _ => throw new ArgumentOutOfRangeException(nameof(index), \"Indices for Color3 run from 0 to 2, inclusive.\"),\n            };\n        }\n\n        set\n        {\n            switch (index)\n            {\n                case 0: R = value; break;\n                case 1: G = value; break;\n                case 2: B = value; break;\n                default: throw new ArgumentOutOfRangeException(nameof(index), \"Indices for Color3 run from 0 to 2, inclusive.\");\n            }\n        }\n    }\n\n    /// <summary>\n    /// Converts the color into a packed integer.\n    /// </summary>","sourceCodeStart":136,"sourceCodeEnd":172,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/core/Stride.Core.Mathematics/Color3.cs#L136-L172","documentation":"Color3's indexer getter accepts only indices 0-2, mapping to R, G, B. Since Color3 has no alpha component, any other index has nothing to return and ArgumentOutOfRangeException is thrown. Guard against treating a Color3 like a 4-channel Color.","triggerScenarios":"Reading color3[index] with index < 0 or index > 2, typically a loop running to 4 because the code was written for Color/Color4.","commonSituations":"Shared per-pixel loops that use a hardcoded channel count of 4; generic component-copy utilities parameterized for 4 channels; porting code from Color to Color3 without updating bounds.","solutions":["Limit iteration to 0..2 for Color3.","If you need 4 channels, use Color or Color4 instead of Color3.","Read R/G/B fields directly instead of the indexer when the component is known."],"exampleFix":"// before\nfor (int i = 0; i < 4; i++)\n    sum += color3[i];\n// after\nfor (int i = 0; i < 3; i++)\n    sum += color3[i];","handlingStrategy":"validation","validationCode":"if (index < 0 || index > 2) throw new ArgumentOutOfRangeException(nameof(index));\nvar channel = color3[index];","typeGuard":"bool IsValidColor3Index(int i) => i is >= 0 and <= 2;","tryCatchPattern":"try { var c = color3[index]; }\ncatch (ArgumentOutOfRangeException) { /* use a 3-channel loop bound */ }","preventionTips":["Use per-type constants (Color3 -> 3 channels) for loop bounds.","Switch to Color/Color4 when 4-channel access is needed.","Access R/G/B fields directly instead of indexing."],"tags":["argument-out-of-range","indexing","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"}