stride3d/stride · error · ArgumentException

. is not enough to copy.

Error message

{ nameof(heightStickArray) }.{ nameof(heightStickArray.Length) } is not enough to copy.

What it means

After selecting the heights buffer, CopyTo verifies the destination heightstick array is at least as long as the source heights array. If heightStickArrayLength < heights.Length it throws ArgumentException: the destination cannot hold all height samples, so the copy would overflow.

Solutions

  1. Size the HeightStickArrayDescription (width/length of samples) to match the Heightmap dimensions exactly.
  2. Compute the stick array length as numRows * numColumns matching the heights array length before calling CopyTo.
  3. Crop or resample the Heightmap data to fit the allocated stick array.

Example fix

// before
var desc = new HeightStickArrayDescription(128, 128); // too small
source.CopyTo<short>(stickArray, 0); // ArgumentException
// after
var desc = new HeightStickArrayDescription(heightmap.Height, heightmap.Width); // matches source
source.CopyTo<short>(stickArray, 0);
Defensive patterns

Strategy: validation

Validate before calling

if (stickArrayLength < heights.Length)
    throw new InvalidOperationException("HeightStickArray too small for heightmap data.");

Try / catch

try { source.CopyTo<short>(stickArray, 0); }
catch (ArgumentException e) { Console.WriteLine($"Resize stick array: {e.Message}"); }

Prevention

When it happens

Trigger: Calling CopyTo with a heightstick array sized for a smaller terrain grid than the Heightmap provides, e.g. heightmap 256x256 but stick array sized 128x128.

Common situations: Mismatch between terrain asset resolution and the physics HeightStickArrayDescription dimensions; forgetting that length includes both X and Z sample counts multiplied.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


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

Appendix: source

Thrown at sources/engine/Stride.Physics/HeightStickArraySourceFromHeightmap.cs:66

                heights = (T[])(object)Heightmap.Floats;
            }
            else if (typeOfT == typeof(short))
            {
                if (Heightmap.Shorts == null) throw new InvalidOperationException($"{ nameof(Heightmap.Shorts) } is a null.");
                heights = (T[])(object)Heightmap.Shorts;
            }
            else if (typeOfT == typeof(byte))
            {
                if (Heightmap.Bytes == null) throw new InvalidOperationException($"{ nameof(Heightmap.Bytes) } is a null.");
                heights = (T[])(object)Heightmap.Bytes;
            }
            else
            {
                throw new NotSupportedException($"{ typeof(UnmanagedArray<T>) } type is not supported.");
            }

            var heightsLength = heights.Length;
            if (heightStickArrayLength < heightsLength) throw new ArgumentException($"{ nameof(heightStickArray) }.{ nameof(heightStickArray.Length) } is not enough to copy.");

            heightStickArray.Write(heights, index * Unsafe.SizeOf<T>(), 0, heightsLength);
        }

        public bool Match(object obj)
        {
            var other = obj as HeightStickArraySourceFromHeightmap;

            if (other == null)
            {
                return false;
            }

            return other.Heightmap == Heightmap;
        }
    }
}

View on GitHub (pinned to 96fad776d2)