{"record":{"id":"cf368447dbe02f78","repo":"stride3d/stride","slug":"there-must-be-two-and-only-two-input-values-for-vector2","errorCode":null,"errorMessage":"There must be two and only two input values for Vector2.","messagePattern":"There must be two and only two input values for Vector2\\.","errorType":"exception","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"sources/core/Stride.Core.Mathematics/Vector2.cs","lineNumber":113,"sourceCode":"    /// <param name=\"y\">Initial value for the Y component of the vector.</param>\n    public Vector2(float x, float y)\n    {\n        X = x;\n        Y = y;\n    }\n\n    /// <summary>\n    /// Initializes a new instance of the <see cref=\"Stride.Core.Mathematics.Vector2\"/> 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 Vector2(float[] values)\n    {\n        if (values == null)\n            throw new ArgumentNullException(nameof(values));\n        if (values.Length != 2)\n            throw new ArgumentOutOfRangeException(nameof(values), \"There must be two and only two input values for Vector2.\");\n\n        X = values[0];\n        Y = values[1];\n    }\n\n    /// <summary>\n    /// Gets a value indicting whether this instance is normalized.\n    /// </summary>\n    public bool IsNormalized\n    {\n        get { return MathF.Abs((X * X) + (Y * Y) - 1f) < MathUtil.ZeroTolerance; }\n    }\n\n    /// <summary>\n    /// Gets or sets the component at the specified index.\n    /// </summary>\n    /// <value>The value of the X or Y component, depending on the index.</value>\n    /// <param name=\"index\">The index of the component to access. Use 0 for the X component and 1 for the Y component.</param>","sourceCodeStart":95,"sourceCodeEnd":131,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/core/Stride.Core.Mathematics/Vector2.cs#L95-L131","documentation":"Array-constructor guard on Vector2(float[] values): the values array does not contain exactly two elements, so X and Y cannot both be initialized from it. The faulting input is the values array length.","triggerScenarios":"Calling new Vector2(array) with arrays of length 0, 1, 3 or more, e.g. a 3-element position array truncated or a 4-element RGBA array passed by mistake.","commonSituations":"Passing vertex data flattened as xyz triples; deserializing 2D data that gained extra components; reusing a conversion helper built for Vector3 arrays; mixing 2D/3D asset pipelines.","solutions":["Ensure the array has exactly 2 elements before constructing (slice, pad, or truncate).","Use the explicit Vector2(x, y) constructor when components are known individually.","Fix the data-extraction code to produce a 2-element array (e.g. new float[]{ data[0], data[1] })."],"exampleFix":"// before\nvar v = new Vector2(position); // position is float[3]\n// after\nvar v = new Vector2(position[0], position[1]);","handlingStrategy":"validation","validationCode":"if (values == null)\n    throw new ArgumentNullException(nameof(values));\nif (values.Length != 2)\n    throw new ArgumentException($\"Vector2 requires exactly 2 values, got {values.Length}.\", nameof(values));\nvar v = new Vector2(values);","typeGuard":null,"tryCatchPattern":"try\n{\n    var v = new Vector2(values);\n}\ncatch (ArgumentOutOfRangeException ex)\n{\n    logger.LogError(ex, \"Vector2 construction failed with {Count} values\", values?.Length);\n}","preventionTips":["Prefer the explicit Vector2(x, y) constructor.","Slice or truncate multi-component arrays (e.g. xyz triples) to 2 elements before constructing.","Keep 2D and 3D data pipelines separated to avoid passing 3-element arrays."],"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"}