{"record":{"id":"7d907148a7c2ffd9","repo":"stride3d/stride","slug":"there-must-be-four-and-only-four-input-values-for-vector4","errorCode":null,"errorMessage":"There must be four and only four input values for Vector4.","messagePattern":"There must be four and only four input values for Vector4\\.","errorType":"exception","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"sources/core/Stride.Core.Mathematics/Vector4.cs","lineNumber":167,"sourceCode":"    public Vector4(Vector2 value, float z, float 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=\"Vector4\"/> 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 Vector4(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 Vector4.\");\n\n        X = values[0];\n        Y = values[1];\n        Z = values[2];\n        W = values[3];\n    }\n\n    /// <summary>\n    /// Gets a value indicting whether this instance is normalized.\n    /// </summary>\n    public readonly bool IsNormalized\n    {\n        get { return MathF.Abs((X * X) + (Y * Y) + (Z * Z) + (W * W) - 1f) < MathUtil.ZeroTolerance; }\n    }\n\n    /// <summary>\n    /// Gets or sets the component at the specified index.\n    /// </summary>","sourceCodeStart":149,"sourceCodeEnd":185,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/core/Stride.Core.Mathematics/Vector4.cs#L149-L185","documentation":"The Vector4(float[] values) constructor requires exactly four elements to fill X, Y, Z, W. When values.Length != 4 it throws ArgumentOutOfRangeException with 'There must be four and only four input values for Vector4.' A null array throws ArgumentNullException separately.","triggerScenarios":"new Vector4(someArray) where someArray has fewer or more than 4 elements — e.g. a 3-element RGB array, an empty array, or a concatenated buffer.","commonSituations":"Building a Vector4 from color data stored as 3 components (RGB without alpha); parsing flat buffers into vectors with the wrong stride; off-by-one slicing of a float buffer.","solutions":["Validate the array length is 4 before constructing","Pad 3-component data explicitly with a fourth value (e.g. alpha = 1f) instead of relying on the constructor","Slice the buffer precisely: new Vector4(buffer.Skip(offset).Take(4).ToArray()) after checking bounds"],"exampleFix":"// before\nvar v = new Vector4(rgbArray); // length 3\n// after\nvar v = rgbArray.Length == 3\n    ? new Vector4(rgbArray[0], rgbArray[1], rgbArray[2], 1f)\n    : new Vector4(rgbArray);","handlingStrategy":"validation","validationCode":"if (values == null || values.Length != 4)\n    throw new ArgumentException(\"Vector4 requires exactly 4 float values\", nameof(values));\nvar v = new Vector4(values);","typeGuard":"static bool IsVector4Tuple(float[] values) => values is { Length: 4 };","tryCatchPattern":"try\n{\n    var v = new Vector4(values);\n}\ncatch (ArgumentOutOfRangeException)\n{\n    // pad or reslice to exactly 4 elements before retrying\n}","preventionTips":["Check array length before constructing fixed-size vectors","Pad RGB→RGBA explicitly rather than relying on the constructor","Use constructor overloads new Vector4(x, y, z, w) when components are known individually"],"tags":["csharp","argument-out-of-range","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-23T08:17:48.524Z"}