stride3d/stride · error · ArgumentNullException
Value cannot be null. (Parameter 'source')
Error message
Value cannot be null. (Parameter 'source')
What it means
Thrown by a Vector3 array-transform method (Gram-Schmidt orthogonalization helper) when the source array is null. The method loops over source elements to build orthogonal vectors, so a null source is rejected immediately with ArgumentNullException.
Solutions
- Allocate the source array before calling, e.g. new Vector3[n]
- Null-check and early-return when there is no data to transform
- Fix the loader that returned null instead of an empty array
Example fix
// before Vector3Helper.Orthonormalize(source, destination); // source null // after if (source == null || source.Length == 0) return; Vector3Helper.Orthonormalize(source, destination);
Defensive patterns
Strategy: validation
Validate before calling
if (source == null || source.Length == 0) return; // nothing to transform
Type guard
static bool HasData(Vector3[] a) => a != null && a.Length > 0;
Try / catch
try { Transform(source, destination); }
catch (ArgumentNullException ex) when (ex.ParamName == "source") { /* skip or allocate */ } Prevention
- Check mesh/vertex arrays for null before batch math
- Make loaders return empty arrays instead of null
- Assert non-null arrays in debug builds before transforms
When it happens
Trigger: Calling the transform/orthonormalize API with a null source array, e.g. from an uninitialized vertex/normal array or a null return from a mesh loader.
Common situations: Mesh processing pipelines where an empty attribute loaded as null; refactoring that moved array creation after the transform call.
Related errors
- Value cannot be null. (Parameter 'destination')
- 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/5c60c26e35e2bd9c.
Report an issue: GitHub.
Appendix: source
Thrown at sources/core/Stride.Core.Mathematics/Vector3.cs:1044
/// list.</para>
/// <para>Because this method uses the modified Gram-Schmidt process, the resulting vectors
/// 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;
}
}
View on GitHub (pinned to 96fad776d2)