stride3d/stride · error · ArgumentException

UnmanagedArray .Length is not enough to fill.

Error message

UnmanagedArray<T>.Length is not enough to fill.

What it means

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.'

Solutions

  1. Reduce fillLength so index + fillLength <= array.Length
  2. Clamp fillLength to Math.Min(fillLength, array.Length - index) before calling
  3. Allocate a larger UnmanagedArray if more data truly must be written

Example fix

// before
array.Fill(value, 10, array.Length); // overruns
// after
array.Fill(value, 10, array.Length - 10);
Defensive patterns

Strategy: validation

Validate before calling

var clamped = Math.Min(fillLength, array.Length - index);
if (clamped > 0) array.Fill(value, index, clamped);

Type guard

static bool FitsFill<T>(UnmanagedArray<T> a, int index, int len) where T : struct => a != null && index >= 0 && len >= 0 && index + len <= a.Length;

Try / catch

try { array.Fill(value, index, fillLength); } catch (ArgumentException) { /* fill range exceeds buffer length */ }

Prevention

When it happens

Trigger: 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.

Common situations: Assuming Fill behaves like Array.Fill over remaining space, or passing a total capacity instead of the remaining count as fillLength.

Related errors


AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14). Data as JSON: /api/errors/8406c359f6988fce. Report an issue: GitHub.

Appendix: source

Thrown at sources/engine/Stride.Physics/UnmanagedArrayExtensions.cs:26

    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)