stride3d/stride · error · IndexOutOfRangeException
index
Error message
index
What it means
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.
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
Example fix
// before array.Fill(value, array.Length, 10); // index == length -> throws // after if (index < array.Length) array.Fill(value, index, 10);
Defensive patterns
Strategy: validation
Validate before calling
if (index < array.Length)
array.Fill(value, index, fillLength); Type guard
static bool CanFillAt<T>(UnmanagedArray<T> a, int index) where T : struct => a != null && index >= 0 && index < a.Length;
Try / catch
try { array.Fill(value, index, fillLength); } catch (IndexOutOfRangeException) { /* index beyond buffer */ } Prevention
- Recompute offsets from the current Length after any resize
- Never use stale offsets captured before reallocation
When it happens
Trigger: Calling array.Fill(value, index, fillLength) where index >= array.Length, e.g. filling from a stale offset after the array was resized smaller.
Common situations: Using offsets computed from a previous allocation size, or off-by-one where index equals the length.
Related errors
- This manifold is empty
- IndexOutOfRangeException: index
- unmanagedArray
- UnmanagedArray .Length is not enough to fill.
- Indices for Double3 run from 0 to 2, inclusive.
AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14).
Data as JSON: /api/errors/e3fc8447ac9184c4.
Report an issue: GitHub.
Appendix: source
Thrown at sources/engine/Stride.Physics/UnmanagedArrayExtensions.cs:25
{
public static class UnmanagedArrayExtensions
{
/// <summary>
/// Fill the array with specific value.
/// </summary>
/// <typeparam name="T">The type param of UnmanagedArray</typeparam>
/// <param name="unmanagedArray">The destination to fill.</param>
/// <param name="value">The value used to fill.</param>
/// <param name="index">The start index of the destination to fill.</param>
/// <param name="fillLength">The filling length.</param>
public static void Fill<T>(this UnmanagedArray<T> unmanagedArray, T value, int index, int fillLength) where T : struct
{
if (unmanagedArray == null) throw new ArgumentNullException(nameof(unmanagedArray));
var length = unmanagedArray.Length;
var endIndex = index + fillLength;
if (length <= index) throw new IndexOutOfRangeException(nameof(index));
if (length < endIndex) throw new ArgumentException($"{ nameof(unmanagedArray) }.{ nameof(unmanagedArray.Length) } is not enough to fill.");
for (int i = index; i < endIndex; ++i)
{
unmanagedArray[i] = value;
}
}
}
}
View on GitHub (pinned to 96fad776d2)