{"record":{"id":"fafda10a3f787242","repo":"stride3d/stride","slug":"there-must-be-four-and-only-four-input-values-for-uint4","errorCode":null,"errorMessage":"There must be four and only four input values for UInt4.","messagePattern":"There must be four and only four input values for UInt4\\.","errorType":"exception","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"sources/core/Stride.Core.Mathematics/UInt4.cs","lineNumber":130,"sourceCode":"    {\n        X = x;\n        Y = y;\n        Z = z;\n        W = w;\n    }\n\n    /// <summary>\n    ///   Initializes a new instance of the <see cref = \"UInt4\" /> struct.\n    /// </summary>\n    /// <param name = \"values\">The values to assign to the X, Y, Z, and W components of the vector. 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 UInt4(uint[] values)\n    {\n        if (values == null)\n            throw new ArgumentNullException(nameof(values));\n        if (values.Length != 4)\n            throw new ArgumentOutOfRangeException(nameof(values), \"There must be four and only four input values for UInt4.\");\n\n        X = values[0];\n        Y = values[1];\n        Z = values[2];\n        W = values[3];\n    }\n\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 uint this[uint index]\n    {\n        get\n        {","sourceCodeStart":112,"sourceCodeEnd":148,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/core/Stride.Core.Mathematics/UInt4.cs#L112-L148","documentation":"The UInt4(uint[] values) constructor requires the input array to contain exactly four elements, one for each component X, Y, Z, W. If the array length differs from 4 (and is not null), ArgumentOutOfRangeException is thrown with this message.","triggerScenarios":"Calling new UInt4(array) with an array whose Length is not 4, e.g. a 3-element array from deserialized data or a padded 5-element buffer.","commonSituations":"Deserializing packed data that lost a component; passing a Vector3/Color components array (3 elements) instead of 4; building the array with a loop that miscounts; upstream format change from RGB to RGBA or vice versa.","solutions":["Ensure the array has exactly 4 elements before constructing: pad with 0 or truncate as appropriate.","Check the data source's component count (3 vs 4 channels) and adapt it to four.","Use a fixed-size alternative or explicit constructor UInt4(x, y, z, w) when element count is known at compile time."],"exampleFix":"// before\nvar v = new UInt4(rgbaBuffer); // rgbaBuffer.Length may be 3\n// after\nif (rgbaBuffer.Length != 4)\n    Array.Resize(ref rgbaBuffer, 4);\nvar v = new UInt4(rgbaBuffer);","handlingStrategy":"validation","validationCode":"if (values == null)\n    throw new ArgumentNullException(nameof(values));\nif (values.Length != 4)\n    throw new ArgumentException($\"UInt4 requires exactly 4 values, got {values.Length}.\", nameof(values));\nvar v = new UInt4(values);","typeGuard":null,"tryCatchPattern":"try\n{\n    var v = new UInt4(values);\n}\ncatch (ArgumentOutOfRangeException ex)\n{\n    // wrong element count — inspect ex.ParamName/values.Length and fix the data source\n    logger.LogError(ex, \"UInt4 construction failed with {Count} values\", values?.Length);\n}","preventionTips":["Prefer the explicit UInt4(x, y, z, w) constructor over array input.","Assert array length 4 at deserialization boundaries.","Keep component counts consistent between data formats (RGB vs RGBA) and vector types."],"tags":["mathematics","argument-out-of-range","array-length"],"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-23T08:17:48.524Z"}