{"record":{"id":"b9a5f601aa8b2ba7","repo":"stride3d/stride","slug":"there-must-be-three-and-only-three-input-values-for-color3","errorCode":null,"errorMessage":"There must be three and only three input values for Color3.","messagePattern":"There must be three and only three input values for Color3\\.","errorType":"exception","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"sources/core/Stride.Core.Mathematics/Color3.cs","lineNumber":131,"sourceCode":"    /// The alpha component is ignored.</param>\n    public Color3(uint rgb)\n    {\n        B = ((rgb >> 16) & 255) / 255.0f;\n        G = ((rgb >> 8) & 255) / 255.0f;\n        R = (rgb & 255) / 255.0f;\n    }\n\n    /// <summary>\n    /// Initializes a new instance of the <see cref=\"Color3\"/> struct.\n    /// </summary>\n    /// <param name=\"values\">The values to assign to the red, green, and blue components of the color. This must be an array with three elements.</param>\n    /// <exception cref=\"ArgumentNullException\">Thrown when <paramref name=\"values\"/> is <c>null</c>.</exception>\n    /// <exception cref=\"ArgumentOutOfRangeException\">Thrown when <paramref name=\"values\"/> contains more or less than four elements.</exception>\n    public Color3(float[] values)\n    {\n        ArgumentNullException.ThrowIfNull(values);\n        if (values.Length != 3)\n            throw new ArgumentOutOfRangeException(nameof(values), \"There must be three and only three input values for Color3.\");\n\n        R = values[0];\n        G = values[1];\n        B = values[2];\n    }\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","sourceCodeStart":113,"sourceCodeEnd":149,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/core/Stride.Core.Mathematics/Color3.cs#L113-L149","documentation":"The Color3(float[]) constructor requires the array to contain exactly three values (R, G, B). Passing null throws ArgumentNullException; passing an array of any other length throws ArgumentOutOfRangeException with this message. Note the XML doc incorrectly says 'four elements' — the code enforces three.","triggerScenarios":"new Color3(new float[]{0.1f, 0.2f}) or new Color3(rgbaFloatArrayOf4) — any float[] whose Length != 3.","commonSituations":"Reusing an RGBA buffer (4 floats) from Color4/Color code paths; passing an array built for another math type (Vector4, Color4); parsing config where an extra alpha value was included.","solutions":["Pass an array of exactly 3 floats, or slice: new Color3(values[..3]).","If the source is RGBA and alpha should be dropped, build Color3(values[0], values[1], values[2]).","Validate values.Length == 3 before constructing."],"exampleFix":"// before\nvar color = new Color3(rgbaArray); // rgbaArray.Length == 4\n// after\nvar color = new Color3(rgbaArray[0], rgbaArray[1], rgbaArray[2]);","handlingStrategy":"validation","validationCode":"if (values is { Length: 3 })\n    var c = new Color3(values);\nelse\n    throw new ArgumentException(\"Color3 requires exactly 3 floats\", nameof(values));","typeGuard":"bool IsRgbTriple(float[] v) => v is { Length: 3 };","tryCatchPattern":"try { var c = new Color3(values); }\ncatch (ArgumentOutOfRangeException) { /* handle wrong-size input, e.g. slice or default */ }","preventionTips":["Slice RGBA arrays to [..3] before constructing a Color3.","Validate array length at deserialization boundaries.","Note the XML doc on this constructor says 'four elements' but the code requires 3 — trust the message."],"tags":["argument-out-of-range","constructor","csharp"],"backgroundTag":"argument-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"}