{"record":{"id":"23faae3e9071bcb6","repo":"stride3d/stride","slug":"there-must-be-two-and-only-two-input-values-for-half2","errorCode":null,"errorMessage":"There must be two and only two input values for Half2.","messagePattern":"There must be two and only two input values for Half2\\.","errorType":"exception","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"sources/core/Stride.Core.Mathematics/Half2.cs","lineNumber":106,"sourceCode":"    /// </summary>\n    /// <param name=\"value\">The value to set for both the X and Y components.</param>\n    public Half2(Half value)\n    {\n        X = value;\n        Y = value;\n    }\n\n    /// <summary>\n    /// Initializes a new instance of the <see cref=\"Half2\"/> struct.\n    /// </summary>\n    /// <param name=\"values\">The values to assign to the X and Y components of the vector. This must be an array with two 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 two elements.</exception>\n    public Half2(Half[] values)\n    {\n        ArgumentNullException.ThrowIfNull(values);\n        if (values.Length != 2)\n            throw new ArgumentOutOfRangeException(nameof(values), \"There must be two and only two input values for Half2.\");\n\n        X = values[0];\n        Y = values[1];\n    }\n\n    /// <summary>\n    /// Initializes a new instance of the <see cref=\"Half2\"/> structure.\n    /// </summary>\n    /// <param name=\"x\">The X component.</param>\n    /// <param name=\"y\">The Y component.</param>\n    public Half2(float x, float y)\n    {\n        X = (Half)x;\n        Y = (Half)y;\n    }\n\n    /// <summary>\n    /// Initializes a new instance of the <see cref=\"Half2\"/> structure.","sourceCodeStart":88,"sourceCodeEnd":124,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/core/Stride.Core.Mathematics/Half2.cs#L88-L124","documentation":"Thrown by the Half2(Half[]) constructor when the input array does not contain exactly two elements. Half2 is a fixed-size 2-component vector (X, Y), so it can only be built from exactly two Half values. Thrown as ArgumentOutOfRangeException for the 'values' parameter.","triggerScenarios":"Calling new Half2(Half[]) with an array of length 0, 1, or 3+ — e.g. passing a Half3's raw component array or an empty placeholder array.","commonSituations":"Unpacking packed half-float buffers where the stride/offset math is off by one; passing half-precision UV data that includes an extra padding element; converting from float arrays without converting length.","solutions":["Ensure the array has exactly 2 elements before constructing","If data is 3D, use Half3 instead of Half2","Slice the array to exactly two elements when extracting from a larger buffer"],"exampleFix":"// before\nvar uv = new Half2(halfs); // halfs.Length == 3 -> throws\n// after\nvar uv = new Half2(new[] { halfs[0], halfs[1] });","handlingStrategy":"validation","validationCode":"if (values is null) throw new ArgumentNullException(nameof(values));\nif (values.Length != 2) throw new ArgumentException($\"Half2 requires exactly 2 values, got {values.Length}.\", nameof(values));","typeGuard":"static bool IsValidHalf2Source(Half[]? values) => values is { Length: 2 };","tryCatchPattern":"try { var v = new Half2(values); }\ncatch (ArgumentOutOfRangeException ex) when (ex.ParamName == \"values\")\n{\n    // handle malformed packed data\n    var v = new Half2(Half.Zero, Half.Zero);\n}","preventionTips":["Validate array length is exactly 2 before constructing","Verify buffer stride/offset math when unpacking packed half data","Prefer the (Half x, Half y) component constructor over array construction"],"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"}