{"record":{"id":"0dabcc6c7f592a0f","repo":"stride3d/stride","slug":"there-must-be-four-and-only-four-input-values-for-double4","errorCode":null,"errorMessage":"There must be four and only four input values for Double4.","messagePattern":"There must be four and only four input values for Double4\\.","errorType":"exception","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"sources/core/Stride.Core.Mathematics/Double4.cs","lineNumber":141,"sourceCode":"    public Double4(Double2 value, double z, double w)\n    {\n        X = value.X;\n        Y = value.Y;\n        Z = z;\n        W = w;\n    }\n\n    /// <summary>\n    /// Initializes a new instance of the <see cref=\"Double4\"/> 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 Double4(double[] 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 Double4.\");\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=\"Double4\"/> struct.\n    /// </summary>\n    /// <param name=\"v\">The Vector4 to construct the Double4 from.</param>\n    public Double4(Vector4 v)\n    {\n        X = v.X;\n        Y = v.Y;\n        Z = v.Z;\n        W = v.W;\n    }","sourceCodeStart":123,"sourceCodeEnd":159,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/core/Stride.Core.Mathematics/Double4.cs#L123-L159","documentation":"Thrown by the Double4(double[]) constructor when the input array does not contain exactly four elements. Double4 is a fixed-size 4-component vector (X, Y, Z, W), so it can only be built from exactly four doubles. The library throws ArgumentOutOfRangeException naming the 'values' parameter to fail fast instead of silently padding or truncating.","triggerScenarios":"Calling new Double4(double[]) with an array whose Length is not 4 — e.g. an empty array, a 3-element array missing W, or a 5-element array from parsing a longer data file.","commonSituations":"Loading vector data from files or network payloads where a record has fewer/more fields than expected; slicing a larger buffer with wrong start/end indices; converting from 3D data (xyz) to 4D (xyzw) and forgetting the W component.","solutions":["Ensure the array passed to the constructor has exactly 4 elements before constructing","If data has fewer components, add the missing one explicitly (e.g. W = 0 or 1) before constructing","Use a 3-component type (Double3) if the data is genuinely 3D instead of padding into Double4","Log the actual values.Length to identify where the malformed array originates"],"exampleFix":"// before\nvar v = new Double4(values); // values.Length == 3 -> throws\n// after\nif (values.Length != 4)\n    throw new ArgumentException($\"Expected 4 values, got {values.Length}\", nameof(values));\nvar v = new Double4(values);","handlingStrategy":"validation","validationCode":"if (values is null) throw new ArgumentNullException(nameof(values));\nif (values.Length != 4) throw new ArgumentException($\"Double4 requires exactly 4 values, got {values.Length}.\", nameof(values));","typeGuard":"static bool IsValidDouble4Source(double[]? values) => values is { Length: 4 };","tryCatchPattern":"try { var v = new Double4(values); }\ncatch (ArgumentOutOfRangeException ex) when (ex.ParamName == \"values\")\n{\n    // fall back to default vector or report malformed input\n    var v = Double4.Zero;\n}","preventionTips":["Validate array length with a pattern check (values is { Length: 4 }) before constructing","Centralize vector construction in a helper that pads/truncates data deliberately","Prefer strongly-typed component constructors (new Double4(x, y, z, w)) over array constructors","Assert lengths at deserialization boundaries where vector data enters the system"],"tags":["argument-out-of-range","mathematics","vector","constructor","csharp"],"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"}