{"record":{"id":"db0f495e0de812ec","repo":"stride3d/stride","slug":"there-must-be-four-and-only-four-input-values-for-half4","errorCode":null,"errorMessage":"There must be four and only four input values for Half4.","messagePattern":"There must be four and only four input values for Half4\\.","errorType":"exception","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"sources/core/Stride.Core.Mathematics/Half4.cs","lineNumber":134,"sourceCode":"    public Half4(Half value)\n    {\n        X = value;\n        Y = value;\n        Z = value;\n        W = value;\n    }\n\n    /// <summary>\n    /// Initializes a new instance of the <see cref=\"Half4\"/> 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 Half4(Half[] 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 Half4.\");\n\n        X = values[0];\n        Y = values[1];\n        Z = values[2];\n        W = values[3];\n    }\n\n    /// <summary>\n    /// Initializes a new instance of the <see cref=\"Half4\"/> structure.\n    /// </summary>\n    /// <param name=\"x\">The X component.</param>\n    /// <param name=\"y\">The Y component.</param>\n    /// <param name=\"z\">The Z component.</param>\n    /// <param name=\"w\">The W component.</param>\n    public Half4(float x, float y, float z, float w)\n    {\n        X = (Half)x;\n        Y = (Half)y;","sourceCodeStart":116,"sourceCodeEnd":152,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/core/Stride.Core.Mathematics/Half4.cs#L116-L152","documentation":"Thrown by the Half4(Half[]) constructor when the input array does not contain exactly four elements. Half4 is a fixed-size 4-component vector (X, Y, Z, W), so it can only be built from exactly four Half values. Thrown as ArgumentOutOfRangeException for the 'values' parameter.","triggerScenarios":"Calling new Half4(Half[]) with an array of length 0–3 or 5+, e.g. a truncated packed color/quantized attribute record or an over-long interleaved buffer slice.","commonSituations":"Reading half-precision vertex attributes from binary mesh files with wrong stride; serialized color data missing an alpha channel; end-of-file truncation producing short arrays.","solutions":["Ensure the array has exactly 4 elements before constructing","Verify binary read/stride math so each attribute yields exactly 4 halves","Handle truncated data explicitly at load time instead of passing short arrays to the constructor"],"exampleFix":"// before\nvar c = new Half4(record); // record.Length == 3 -> throws\n// after\nif (record.Length != 4) throw new InvalidDataException($\"Expected 4 halves, got {record.Length}\");\nvar c = new Half4(record);","handlingStrategy":"validation","validationCode":"if (values is null) throw new ArgumentNullException(nameof(values));\nif (values.Length != 4) throw new ArgumentException($\"Half4 requires exactly 4 values, got {values.Length}.\", nameof(values));","typeGuard":"static bool IsValidHalf4Source(Half[]? values) => values is { Length: 4 };","tryCatchPattern":"try { var v = new Half4(values); }\ncatch (ArgumentOutOfRangeException ex) when (ex.ParamName == \"values\")\n{\n    // handle truncated record\n    var v = new Half4(Half.Zero, Half.Zero, Half.Zero, Half.Zero);\n}","preventionTips":["Validate array length is exactly 4 before constructing","Check binary-read return counts and file bounds when loading packed mesh/color data","Prefer the (Half x, Half y, Half z, Half w) component constructor"],"tags":["argument-out-of-range","mathematics","vector","half-float","constructor"],"backgroundTag":"invalid-constructor-argument","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"}