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 Double3's array-based Gram-Schmidt orthogonalization (the method containing this check) when the destination array is shorter than the source. Each orthogonalized vector is written at the same index into destination, so a smaller destination would overflow. Stride validates lengths before the algorithm and throws ArgumentOutOfRangeException naming 'destination'.
Solutions
- Allocate destination with at least source.Length elements: new Double3[source.Length]
- Reuse a scratch buffer only after checking its Length against source.Length
- Confirm source/destination are not reversed
Example fix
// before var dest = new Double3[src.Length / 2]; Double3.Orthogonalize(src, in m, dest); // after var dest = new Double3[src.Length]; Double3.Orthogonalize(src, in m, dest);
Defensive patterns
Strategy: validation
Validate before calling
if (dest is null || dest.Length < src.Length) dest = new Double3[src.Length];
Type guard
static bool CanOrthogonalize(Double3[] src, Double3[] dest) => src != null && dest != null && dest.Length >= src.Length;
Try / catch
try { Double3.Orthogonalize(src, in m, dest); }
catch (ArgumentOutOfRangeException ex) when (ex.ParamName == "destination") { dest = new Double3[src.Length]; Double3.Orthogonalize(src, in m, dest); } Prevention
- Match destination length to source length for every array-based math API
- Use a shared EnsureCapacity helper for pooled buffers
- Keep source/destination in named parameters to avoid swapping them
When it happens
Trigger: Calling the Double3 Orthogonalize-style API (Double3[] source, ref readonly Matrix-ish param, Double3[] destination) with destination.Length < source.Length.
Common situations: Reusing a smaller cached buffer; allocating destination from a different (smaller) array; swapping source/destination arguments by mistake.
Related errors
- Indices for ColorBGRA run from 0 to 3, inclusive.
- There must be three and only three input values for Double3.
- There must be four and only four input values for Double4.
- The destination array must be of same length or larger…
- There must be two and only two input values for Half2.
AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14).
Data as JSON: /api/errors/638103bbc133c234.
Report an issue: GitHub.
Appendix: source
Thrown at sources/core/Stride.Core.Mathematics/Double3.cs:975
/// 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(Double3[] destination, params Double3[] 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)
{
Double3 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)