{"record":{"id":"02d05bdc8a7dec12","repo":"stride3d/stride","slug":"value-cannot-be-null-parameter-destination-vector3","errorCode":null,"errorMessage":"Value cannot be null. (Parameter 'destination')","messagePattern":"Value cannot be null\\. \\(Parameter 'destination'\\)","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"sources/core/Stride.Core.Mathematics/Vector3.cs","lineNumber":1046,"sourceCode":"    /// tend to be numerically unstable. The numeric stability decreases according to the vectors\n    /// position in the list so that the first vector is the most stable and the last vector is the\n    /// least stable.</para>\n    /// </remarks>\n    /// <exception cref=\"ArgumentNullException\">Thrown when <paramref name=\"source\"/> or <paramref name=\"destination\"/> is <c>null</c>.</exception>\n    /// <exception cref=\"ArgumentOutOfRangeException\">Thrown when <paramref name=\"destination\"/> is shorter in length than <paramref name=\"source\"/>.</exception>\n    public static void Orthogonalize(Vector3[] destination, params Vector3[] source)\n    {\n        //Uses the modified Gram-Schmidt process.\n        //q1 = m1\n        //q2 = m2 - ((q1 ⋅ m2) / (q1 ⋅ q1)) * q1\n        //q3 = m3 - ((q1 ⋅ m3) / (q1 ⋅ q1)) * q1 - ((q2 ⋅ m3) / (q2 ⋅ q2)) * q2\n        //q4 = m4 - ((q1 ⋅ m4) / (q1 ⋅ q1)) * q1 - ((q2 ⋅ m4) / (q2 ⋅ q2)) * q2 - ((q3 ⋅ m4) / (q3 ⋅ q3)) * q3\n        //q5 = ...\n\n        if (source == null)\n            throw new ArgumentNullException(nameof(source));\n        if (destination == null)\n            throw new ArgumentNullException(nameof(destination));\n        if (destination.Length < source.Length)\n            throw new ArgumentOutOfRangeException(nameof(destination), \"The destination array must be of same length or larger length than the source array.\");\n\n        for (int i = 0; i < source.Length; ++i)\n        {\n            Vector3 newvector = source[i];\n\n            for (int r = 0; r < i; ++r)\n            {\n                newvector -= (Vector3.Dot(destination[r], newvector) / Vector3.Dot(destination[r], destination[r])) * destination[r];\n            }\n\n            destination[i] = newvector;\n        }\n    }\n\n    /// <summary>\n    /// Orthonormalizes a list of vectors.","sourceCodeStart":1028,"sourceCodeEnd":1064,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/core/Stride.Core.Mathematics/Vector3.cs#L1028-L1064","documentation":"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.","triggerScenarios":"Calling the API with a null destination array — an uninitialized output buffer or a helper that forgot to allocate results.","commonSituations":"Output buffers owned by another subsystem that were never created; asynchronous setups where allocation was skipped on a failure path.","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"],"exampleFix":"// before\nOrthonormalize(source, destination); // destination null\n// after\ndestination ??= new Vector3[source.Length];\nOrthonormalize(source, destination);","handlingStrategy":"validation","validationCode":"destination ??= new Vector3[source.Length];","typeGuard":"static bool IsOutputReady<T>(T[] source, T[] destination) => source != null && destination != null && destination.Length >= source.Length;","tryCatchPattern":"try { Transform(source, destination); }\ncatch (ArgumentNullException ex) when (ex.ParamName == \"destination\") { destination = new Vector3[source.Length]; Transform(source, destination); }","preventionTips":["Allocate output buffers at the same time as inputs","Use ??= for lazy output-buffer allocation","Document output-buffer ownership in helper APIs"],"tags":["csharp","null-argument","vector-math"],"backgroundTag":"null-argument","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"}