stride3d/stride · error · ArgumentNullException

ArgumentNullException: heightStickArray

Error message

ArgumentNullException: heightStickArray

What it means

A validation guard in HeightStickArraySourceFromHeightmap.CopyTo: the destination heightStickArray (the UnmanagedArray the heightmap data is copied into) is invalid/null — the guard fires when the source Heightmap is null or the target array is null. Copying heightfield data into the physics height stick requires both a valid heightmap source and a valid target buffer; either missing triggers ArgumentNullException named 'heightStickArray'.

Solutions

  1. Allocate the UnmanagedArray (sized to HeightStickSize.X * HeightStickSize.Y) before calling CopyTo.
  2. Check the array for null before calling CopyTo.
  3. Verify the heightfield heightstick allocation step ran successfully.

Example fix

// before
source.CopyTo(heightStickArray, 0); // throws if null
// after
heightStickArray ??= new UnmanagedArray<float>(size.X * size.Y);
source.CopyTo(heightStickArray, 0);
Defensive patterns

Strategy: validation

Validate before calling

if (heightStickArray == null)
    throw new InvalidOperationException("Allocate heightstick array before CopyTo");

Try / catch

try { source.CopyTo(heightStickArray, 0); }
catch (ArgumentNullException ex) { /* allocate the buffer and retry */ }

Prevention

When it happens

Trigger: Calling CopyTo with a null UnmanagedArray destination, typically when the heightstick buffer was never allocated for the heightfield.

Common situations: Heightfield collider setup where buffer allocation was skipped; passing an uninitialized variable from a failed earlier setup step.

Related errors


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

Appendix: source

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

        [DataMemberIgnore]
        public HeightfieldTypes HeightType => Heightmap?.HeightType ?? default;

        [DataMemberIgnore]
        public Int2 HeightStickSize => Heightmap?.Size ?? default;

        [DataMemberIgnore]
        public Vector2 HeightRange => Heightmap?.HeightRange ?? default;

        [DataMemberIgnore]
        public float HeightScale => Heightmap?.HeightScale ?? default;

        public bool IsValid() => Heightmap?.IsValid() ?? false;

        public void CopyTo<T>(UnmanagedArray<T> heightStickArray, int index) where T : struct
        {
            if (Heightmap == null) throw new InvalidOperationException($"{ nameof(Heightmap) } is a null");
            if (heightStickArray == null) throw new ArgumentNullException(nameof(heightStickArray));

            var heightStickArrayLength = heightStickArray.Length - index;
            if (heightStickArrayLength <= 0) throw new IndexOutOfRangeException(nameof(index));

            var typeOfT = typeof(T);
            T[] heights;

            if (typeOfT == typeof(float))
            {
                if (Heightmap.Floats == null) throw new InvalidOperationException($"{ nameof(Heightmap.Floats) } is a null.");
                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))

View on GitHub (pinned to 96fad776d2)