stride3d/stride · error · ArgumentNullException

heightStickArray

Error message

heightStickArray

What it means

ByteHeightStickArraySource.CopyTo throws ArgumentNullException when the destination UnmanagedArray 'heightStickArray' is null. This source represents a heightfield fully filled with a constant byte value and needs a valid destination buffer to fill.

Solutions

  1. Allocate the destination UnmanagedArray before calling CopyTo
  2. Check for null before invoking CopyTo

Example fix

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

Strategy: validation

Validate before calling

if (heightStickArray != null)
    byteSource.CopyTo(heightStickArray, index);

Prevention

When it happens

Trigger: Calling CopyTo with a null destination when setting up a heightfield collider from a ByteHeightStickArraySource (e.g. heightfield buffer not yet allocated).

Common situations: Heightfield collider construction where the UnmanagedArray was created lazily and copy is invoked first.

Related errors


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

Appendix: source

Thrown at sources/engine/Stride.Physics/ByteHeightStickArraySource.cs:47

        /// </summary>
        [DataMember(30)]
        [NotNull]
        [Display("HeightScale", Expand = ExpandRule.Always)]
        public IHeightScaleCalculator HeightScaleCalculator { get; set; } = new HeightScaleCalculator();

        /// <summary>
        /// The value to fill the height stick array.
        /// </summary>
        [DataMember(40)]
        [DataMemberRange(0, 255, 1, 10, 0)]
        public byte InitialByte { get; set; } = 0;

        public bool IsValid() => HeightmapUtils.CheckHeightParameters(HeightStickSize, HeightType, HeightRange, HeightScale, false) &&
            MathUtil.IsInRange(InitialByte, byte.MinValue, byte.MaxValue);

        public void CopyTo<T>(UnmanagedArray<T> heightStickArray, int index) where T : struct
        {
            if (heightStickArray == null) throw new ArgumentNullException(nameof(heightStickArray));
            if (heightStickArray is UnmanagedArray<byte> unmanagedArray)
            {
                unmanagedArray.Fill(InitialByte, index, HeightStickSize.X * HeightStickSize.Y);
            }
            else
            {
                throw new NotSupportedException($"{ typeof(UnmanagedArray<T>) } type is not supported.");
            }
        }

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

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

View on GitHub (pinned to 96fad776d2)