{"record":{"id":"2b56054f4707cdbe","repo":"stride3d/stride","slug":"the-destination-array-must-be-of-same-length-or-larger-2b5605","errorCode":null,"errorMessage":"The destination array must be of same length or larger length than the source array.","messagePattern":"The destination array must be of same length or larger length than the source array\\.","errorType":"exception","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"sources/core/Stride.Core.Mathematics/Double4.cs","lineNumber":882,"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(Double4[] destination, params Double4[] 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        ArgumentNullException.ThrowIfNull(source);\n        ArgumentNullException.ThrowIfNull(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            Double4 newvector = source[i];\n\n            for (int r = 0; r < i; ++r)\n            {\n                newvector -= Dot(destination[r], newvector) / Dot(destination[r], destination[r]) * destination[r];\n            }\n\n            destination[i] = newvector;\n        }\n    }\n\n    /// <summary>\n    /// Orthonormalizes a list of vectors.\n    /// </summary>\n    /// <param name=\"destination\">The list of orthonormalized vectors.</param>","sourceCodeStart":864,"sourceCodeEnd":900,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/core/Stride.Core.Mathematics/Double4.cs#L864-L900","documentation":"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.","triggerScenarios":"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.","commonSituations":"Buffer reuse after source grew; allocation sized by a different (smaller) array; off-by-one when excluding a base vector from the destination count.","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"],"exampleFix":"// before\nvar dest = new Double4[source.Length - 1];\nDouble4.Orthogonalize(src, dest); // throws\n// after\nvar dest = new Double4[src.Length];\nDouble4.Orthogonalize(src, dest);","handlingStrategy":"validation","validationCode":"if (source.Length > destination.Length)\n    throw new ArgumentException(\"destination must be at least as long as source.\", nameof(destination));","typeGuard":null,"tryCatchPattern":"try { Double4.Orthogonalize(src, dest); }\ncatch (ArgumentOutOfRangeException ex) when (ex.ParamName == \"destination\")\n{\n    dest = new Double4[src.Length];\n    Double4.Orthogonalize(src, dest);\n}","preventionTips":["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"],"tags":["argument-out-of-range","mathematics","array-size","gram-schmidt","csharp"],"backgroundTag":"argument-out-of-range","analyzedSha":"96fad776d210c221682aac1ccdf4c79dc046fc38","analyzedAt":"2026-09-14T02:59:31.279Z","contentChangedAt":"2026-09-14T02:59:31.279Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}