{"record":{"id":"8406c359f6988fce","repo":"stride3d/stride","slug":"unmanagedarray-t-length-is-not-enough-to-fill","errorCode":null,"errorMessage":"UnmanagedArray<T>.Length is not enough to fill.","messagePattern":"UnmanagedArray<T>\\.Length is not enough to fill\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"sources/engine/Stride.Physics/UnmanagedArrayExtensions.cs","lineNumber":26,"sourceCode":"    public static class UnmanagedArrayExtensions\n    {\n        /// <summary>\n        /// Fill the array with specific value.\n        /// </summary>\n        /// <typeparam name=\"T\">The type param of UnmanagedArray</typeparam>\n        /// <param name=\"unmanagedArray\">The destination to fill.</param>\n        /// <param name=\"value\">The value used to fill.</param>\n        /// <param name=\"index\">The start index of the destination to fill.</param>\n        /// <param name=\"fillLength\">The filling length.</param>\n        public static void Fill<T>(this UnmanagedArray<T> unmanagedArray, T value, int index, int fillLength) where T : struct\n        {\n            if (unmanagedArray == null) throw new ArgumentNullException(nameof(unmanagedArray));\n\n            var length = unmanagedArray.Length;\n            var endIndex = index + fillLength;\n\n            if (length <= index) throw new IndexOutOfRangeException(nameof(index));\n            if (length < endIndex) throw new ArgumentException($\"{ nameof(unmanagedArray) }.{ nameof(unmanagedArray.Length) } is not enough to fill.\");\n\n            for (int i = index; i < endIndex; ++i)\n            {\n                unmanagedArray[i] = value;\n            }\n        }\n    }\n}\n","sourceCodeStart":8,"sourceCodeEnd":35,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/engine/Stride.Physics/UnmanagedArrayExtensions.cs#L8-L35","documentation":"Fill computes endIndex = index + fillLength and throws ArgumentException when the array's Length is smaller than that, i.e. the requested fill range extends beyond the buffer. The message embeds the parameter name: 'UnmanagedArray<T>.Length is not enough to fill.'","triggerScenarios":"Calling array.Fill(value, index, fillLength) where index + fillLength > array.Length, such as filling 100 elements into a 64-element buffer or ignoring that Fill does not clamp.","commonSituations":"Assuming Fill behaves like Array.Fill over remaining space, or passing a total capacity instead of the remaining count as fillLength.","solutions":["Reduce fillLength so index + fillLength <= array.Length","Clamp fillLength to Math.Min(fillLength, array.Length - index) before calling","Allocate a larger UnmanagedArray if more data truly must be written"],"exampleFix":"// before\narray.Fill(value, 10, array.Length); // overruns\n// after\narray.Fill(value, 10, array.Length - 10);","handlingStrategy":"validation","validationCode":"var clamped = Math.Min(fillLength, array.Length - index);\nif (clamped > 0) array.Fill(value, index, clamped);","typeGuard":"static bool FitsFill<T>(UnmanagedArray<T> a, int index, int len) where T : struct => a != null && index >= 0 && len >= 0 && index + len <= a.Length;","tryCatchPattern":"try { array.Fill(value, index, fillLength); } catch (ArgumentException) { /* fill range exceeds buffer length */ }","preventionTips":["Pass the remaining count (Length - index), not total capacity, as fillLength","Add an assertion for index + fillLength <= Length in debug builds"],"tags":["argument-out-of-range","physics","unmanaged-memory"],"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"}