{"record":{"id":"e3fc8447ac9184c4","repo":"stride3d/stride","slug":"index-unmanagedarrayextensions","errorCode":null,"errorMessage":"index","messagePattern":"index","errorType":"exception","errorClass":"IndexOutOfRangeException","httpStatus":null,"severity":"error","filePath":"sources/engine/Stride.Physics/UnmanagedArrayExtensions.cs","lineNumber":25,"sourceCode":"{\n    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":7,"sourceCodeEnd":35,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/engine/Stride.Physics/UnmanagedArrayExtensions.cs#L7-L35","documentation":"Fill throws IndexOutOfRangeException named 'index' when the array length is less than or equal to the requested start index, meaning the fill would begin entirely outside the buffer. The check is length <= index (not index >= 0 only), so even a valid positive index past the end fails.","triggerScenarios":"Calling array.Fill(value, index, fillLength) where index >= array.Length, e.g. filling from a stale offset after the array was resized smaller.","commonSituations":"Using offsets computed from a previous allocation size, or off-by-one where index equals the length.","solutions":["Pass an index strictly less than array.Length","Recompute the start index from the current array Length","Resize the UnmanagedArray if a larger buffer is genuinely needed"],"exampleFix":"// before\narray.Fill(value, array.Length, 10); // index == length -> throws\n// after\nif (index < array.Length) array.Fill(value, index, 10);","handlingStrategy":"validation","validationCode":"if (index < array.Length)\n    array.Fill(value, index, fillLength);","typeGuard":"static bool CanFillAt<T>(UnmanagedArray<T> a, int index) where T : struct => a != null && index >= 0 && index < a.Length;","tryCatchPattern":"try { array.Fill(value, index, fillLength); } catch (IndexOutOfRangeException) { /* index beyond buffer */ }","preventionTips":["Recompute offsets from the current Length after any resize","Never use stale offsets captured before reallocation"],"tags":["index-out-of-range","physics","unmanaged-memory"],"backgroundTag":"index-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"}