stride3d/stride · error · InvalidOperationException

is a null.

Error message

{ nameof(HeightStickArraySource) } is a null.

What it means

HeightfieldColliderShapeDesc.GetCenteringOffset() computes the vertical offset needed to center a heightfield shape. It throws InvalidOperationException when HeightStickArraySource is null, since the height range needed for the calculation is unavailable.

Solutions

  1. Assign a valid HeightStickArraySource (with height data and HeightRange) before building the shape
  2. Validate HeightStickArraySource != null before calling GetCenteringOffset() or creating the shape
  3. If centering is not needed, note it still requires the source because HeightRange comes from it

Example fix

// before
var desc = new HeightfieldColliderShapeDesc();
float offset = desc.GetCenteringOffset(); // throws
// after
desc.HeightStickArraySource = new HeightStickArraySourceDesc { /* height data */ };
float offset = desc.GetCenteringOffset();
Defensive patterns

Strategy: validation

Validate before calling

if (desc.HeightStickArraySource == null)
    throw new InvalidOperationException("HeightStickArraySource must be set before building a heightfield shape.");

Try / catch

try { var offset = desc.GetCenteringOffset(); }
catch (InvalidOperationException) { /* assign HeightStickArraySource and retry */ }

Prevention

When it happens

Trigger: Calling GetCenteringOffset() (directly or via shape creation) on a HeightfieldColliderShapeDesc whose HeightStickArraySource property was never assigned.

Common situations: Creating a heightfield collider from script without populating HeightStickArraySource; a deserialized asset where the heightstick array reference is missing; editor-created shapes where the source data was deleted.

Related errors


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

Appendix: source

Thrown at sources/engine/Stride.Physics/Data/HeightfieldColliderShapeDesc.cs:103

                return null;
            }

            var arrayLength = heightStickArraySource.HeightStickSize.X * heightStickArraySource.HeightStickSize.Y;

            var unmanagedArray = new UnmanagedArray<T>(arrayLength);

            heightStickArraySource.CopyTo(unmanagedArray, 0);

            return unmanagedArray;
        }

        /// <summary>
        /// Get the centering offset that will be added to the local offset of the collider shape.
        /// </summary>
        /// <returns>The value that will be added to the local offset of the collider shape in order to center specific height.</returns>
        public float GetCenteringOffset()
        {
            if (HeightStickArraySource == null) throw new InvalidOperationException($"{ nameof(HeightStickArraySource) } is a null.");

            return Centering.Enabled ?
                GetCenteringOffset(HeightStickArraySource.HeightRange, Centering.CenterHeight) :
                0f;
        }

        public ColliderShape CreateShape(IServiceRegistry services)
        {
            object unmanagedArray;

            switch (HeightStickArraySource.HeightType)
            {
                case HeightfieldTypes.Float:
                {
                    unmanagedArray = CreateHeights<float>(HeightStickArraySource);
                    break;
                }
                case HeightfieldTypes.Short:

View on GitHub (pinned to 96fad776d2)