stride3d/stride · error · ArgumentNullException
Value cannot be null. (Parameter 'destination')
Error message
Value cannot be null. (Parameter 'destination')
What it means
Thrown by the same Vector3 array-transform method when the destination array is null. Results are written into destination per source element, so it must be an allocated array at least as long as source. ArgumentNullException is thrown before any computation.
Solutions
- Allocate destination with destination = new Vector3[source.Length] before the call
- Null-check the output buffer and allocate lazily if needed
- Have the calling function own and clearly initialize all output buffers
Example fix
// before Orthonormalize(source, destination); // destination null // after destination ??= new Vector3[source.Length]; Orthonormalize(source, destination);
Defensive patterns
Strategy: validation
Validate before calling
destination ??= new Vector3[source.Length];
Type guard
static bool IsOutputReady<T>(T[] source, T[] destination) => source != null && destination != null && destination.Length >= source.Length;
Try / catch
try { Transform(source, destination); }
catch (ArgumentNullException ex) when (ex.ParamName == "destination") { destination = new Vector3[source.Length]; Transform(source, destination); } Prevention
- Allocate output buffers at the same time as inputs
- Use ??= for lazy output-buffer allocation
- Document output-buffer ownership in helper APIs
When it happens
Trigger: Calling the API with a null destination array — an uninitialized output buffer or a helper that forgot to allocate results.
Common situations: Output buffers owned by another subsystem that were never created; asynchronous setups where allocation was skipped on a failure path.
Related errors
- Value cannot be null. (Parameter 'source')
- ArgumentNullException: generator
- ArgumentNullException: parameters
- builder
- Cannot add a null UIElement to the children list.
AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14).
Data as JSON: /api/errors/02d05bdc8a7dec12.
Report an issue: GitHub.
Appendix: source
Thrown at sources/core/Stride.Core.Mathematics/Vector3.cs:1046
/// 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(Vector3[] destination, params Vector3[] 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 = ...
if (source == null)
throw new ArgumentNullException(nameof(source));
if (destination == null)
throw new ArgumentNullException(nameof(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)
{
Vector3 newvector = source[i];
for (int r = 0; r < i; ++r)
{
newvector -= (Vector3.Dot(destination[r], newvector) / Vector3.Dot(destination[r], destination[r])) * destination[r];
}
destination[i] = newvector;
}
}
/// <summary>
/// Orthonormalizes a list of vectors.View on GitHub (pinned to 96fad776d2)