{"record":{"id":"a07ff8153aa1c32b","repo":"stride3d/stride","slug":"there-must-be-four-and-only-four-input-values-for-colorbgra","errorCode":null,"errorMessage":"There must be four and only four input values for ColorBGRA.","messagePattern":"There must be four and only four input values for ColorBGRA\\.","errorType":"exception","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"sources/core/Stride.Core.Mathematics/ColorBGRA.cs","lineNumber":151,"sourceCode":"    public ColorBGRA(int bgra)\n    {\n        A = (byte)((bgra >> 24) & 255);\n        R = (byte)((bgra >> 16) & 255);\n        G = (byte)((bgra >> 8) & 255);\n        B = (byte)(bgra & 255);\n    }\n\n    /// <summary>\n    /// Initializes a new instance of the <see cref=\"ColorBGRA\"/> struct.\n    /// </summary>\n    /// <param name=\"values\">The values to assign to the red, green, and blue, alpha components of the color. This must be an array with four 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 ColorBGRA(float[] values)\n    {\n        ArgumentNullException.ThrowIfNull(values);\n        if (values.Length != 4)\n            throw new ArgumentOutOfRangeException(nameof(values), \"There must be four and only four input values for ColorBGRA.\");\n\n        B = ToByte(values[0]);\n        G = ToByte(values[1]);\n        R = ToByte(values[2]);\n        A = ToByte(values[3]);\n    }\n\n    /// <summary>\n    /// Initializes a new instance of the <see cref=\"ColorBGRA\"/> struct.\n    /// </summary>\n    /// <param name=\"values\">The values to assign to the red, green, and blue, alpha components of the color. This must be an array with four 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 ColorBGRA(byte[] values)\n    {\n        ArgumentNullException.ThrowIfNull(values);\n        if (values.Length != 4)\n            throw new ArgumentOutOfRangeException(nameof(values), \"There must be four and only four input values for ColorBGRA.\");","sourceCodeStart":133,"sourceCodeEnd":169,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/core/Stride.Core.Mathematics/ColorBGRA.cs#L133-L169","documentation":"The ColorBGRA(float[]) constructor requires exactly four floats in BGRA order (each converted from float to byte). Arrays of any other length throw ArgumentOutOfRangeException, since a BGRA color is defined by exactly four channels.","triggerScenarios":"new ColorBGRA(floatArray) where floatArray.Length != 4 — e.g. 3-element RGB float arrays or longer buffers.","commonSituations":"Passing RGB (no alpha) float data from shaders or image decoders; reusing buffers from Color3 code; channel-order confusion (RGBA vs BGRA) that also changes expected array size in adjacent code.","solutions":["Supply exactly 4 floats in B, G, R, A order.","If you only have RGB, append alpha: new ColorBGRA(r, g, b, 1f) style or new[] {b, g, r, 1f}.","Check array length == 4 before constructing."],"exampleFix":"// before\nvar c = new ColorBGRA(rgbFloats); // Length == 3\n// after\nvar c = new ColorBGRA(new[] { rgbFloats[0], rgbFloats[1], rgbFloats[2], 1f });","handlingStrategy":"validation","validationCode":"if (values is { Length: 4 })\n    var c = new ColorBGRA(values);\nelse\n    throw new ArgumentException(\"ColorBGRA requires exactly 4 floats (B,G,R,A)\", nameof(values));","typeGuard":"bool IsBgraQuad(float[] v) => v is { Length: 4 };","tryCatchPattern":"try { var c = new ColorBGRA(values); }\ncatch (ArgumentOutOfRangeException) { /* pad RGB to BGRA or reject input */ }","preventionTips":["Remember the channel order is B, G, R, A — not RGBA.","Append an alpha value (1f) when converting 3-channel RGB float data.","Validate array length where buffers are sliced or decoded."],"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"}