stride3d/stride · error · ArgumentOutOfRangeException
The destination array must be of same length or larger…
Error message
The destination array must be of same length or larger length than the source array.
What it means
Thrown by Double4.Orthogonalize when the destination array is shorter than the source array. The method writes one orthogonalized vector per source element, so destination must be at least as long as source. Thrown as ArgumentOutOfRangeException for the 'destination' parameter.
Solutions
- Allocate destination with at least source.Length elements before calling Orthogonalize
- Reuse source as destination if in-place orthogonalization is acceptable (check overload support)
- Add a length assertion (System.Diagnostics.Debug.Assert) at the call site
Example fix
// before var dest = new Double4[source.Length - 1]; Double4.Orthogonalize(src, dest); // throws // after var dest = new Double4[src.Length]; Double4.Orthogonalize(src, dest);
Defensive patterns
Strategy: validation
Validate before calling
if (source.Length > destination.Length)
throw new ArgumentException("destination must be at least as long as source.", nameof(destination)); Try / catch
try { Double4.Orthogonalize(src, dest); }
catch (ArgumentOutOfRangeException ex) when (ex.ParamName == "destination")
{
dest = new Double4[src.Length];
Double4.Orthogonalize(src, dest);
} Prevention
- Always size output buffers from source.Length at the call site
- Debug.Assert(destination.Length >= source.Length) near batch math code
- Avoid long-lived scratch buffers sized by earlier inputs; reallocate when counts change
When it happens
Trigger: Calling Double4.Orthogonalize(Double4[] source, Double4[] destination) with destination.Length < source.Length — e.g. reusing a smaller scratch array or allocating destination from a wrong count.
Common situations: Buffer reuse after source grew; allocation sized by a different (smaller) array; off-by-one when excluding a base vector from the destination count.
Related errors
- Indices for ColorBGRA run from 0 to 3, inclusive.
- There must be four and only four input values for Double4.
- There must be two and only two input values for Int2.
- Indices for Int2 run from 0 to 1, inclusive.
- There must be three and only three input values for Int3.
AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14).
Data as JSON: /api/errors/2b56054f4707cdbe.
Report an issue: GitHub.
Appendix: source
Thrown at sources/core/Stride.Core.Mathematics/Double4.cs:882
/// tend to be numerically unstable. The numeric stability decreases according to the vectors
/// position in the list so that the first vector is the most stable and the last vector is the
/// least stable.</para>
/// </remarks>
/// <exception cref="ArgumentNullException">Thrown when <paramref name="source"/> or <paramref name="destination"/> is <c>null</c>.</exception>
/// <exception cref="ArgumentOutOfRangeException">Thrown when <paramref name="destination"/> is shorter in length than <paramref name="source"/>.</exception>
public static void Orthogonalize(Double4[] destination, params Double4[] source)
{
//Uses the modified Gram-Schmidt process.
//q1 = m1
//q2 = m2 - ((q1 ⋅ m2) / (q1 ⋅ q1)) * q1
//q3 = m3 - ((q1 ⋅ m3) / (q1 ⋅ q1)) * q1 - ((q2 ⋅ m3) / (q2 ⋅ q2)) * q2
//q4 = m4 - ((q1 ⋅ m4) / (q1 ⋅ q1)) * q1 - ((q2 ⋅ m4) / (q2 ⋅ q2)) * q2 - ((q3 ⋅ m4) / (q3 ⋅ q3)) * q3
//q5 = ...
ArgumentNullException.ThrowIfNull(source);
ArgumentNullException.ThrowIfNull(destination);
if (destination.Length < source.Length)
throw new ArgumentOutOfRangeException(nameof(destination), "The destination array must be of same length or larger length than the source array.");
for (int i = 0; i < source.Length; ++i)
{
Double4 newvector = source[i];
for (int r = 0; r < i; ++r)
{
newvector -= Dot(destination[r], newvector) / Dot(destination[r], destination[r]) * destination[r];
}
destination[i] = newvector;
}
}
/// <summary>
/// Orthonormalizes a list of vectors.
/// </summary>
/// <param name="destination">The list of orthonormalized vectors.</param>View on GitHub (pinned to 96fad776d2)