stride3d/stride · error · ArgumentException

is 0.

Error message

{ nameof(heightScale) } is 0.

What it means

CheckHeightParameters rejects a heightScale of zero because dividing heights by scale and mapping into the heightfield range would be undefined; Bullet cannot normalize a zero scale. Throws ArgumentException when the scale passed (or Heightmap.HeightScale) is 0.

Solutions

  1. Set HeightScale to a nonzero value appropriate for your terrain (e.g. 1).
  2. If heights are already in final units, set HeightScale to 1 (required for Float type anyway).
  3. Validate with heightmap.IsValid() before constructing the collider.
  4. Fix pipeline code that computes scale so it cannot produce 0 (guard division).

Example fix

// before
heightmap.HeightScale = 0;
heightmap.CheckHeightParameters(true);
// after
heightmap.HeightScale = 1.0f;
heightmap.CheckHeightParameters(true);
Defensive patterns

Strategy: validation

Validate before calling

if (MathUtil.IsZero(heightScale)) heightScale = 1f;

Type guard

bool ValidScale(float s) => !MathUtil.IsZero(s);

Try / catch

try { CheckHeightParameters(size, type, range, scale, true); } catch (ArgumentException) { /* prompt for a nonzero scale */ }

Prevention

When it happens

Trigger: Calling CheckHeightParameters with heightScale == 0; a Heightmap whose HeightScale property was never set and defaults to 0.

Common situations: Fresh Heightmap objects where only Size and heights were assigned; UI/config where scale field was left at 0; multiplying scale by an external factor that became zero.

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/95f9dda292c77473. Report an issue: GitHub.

Appendix: source

Thrown at sources/engine/Stride.Physics/Engine/HeightmapUtils.cs:26

{
    public class HeightmapUtils
    {
        public static bool CheckHeightParameters(Int2 size, HeightfieldTypes heightType, Vector2 heightRange, float heightScale, bool throwExceptionWhenInvalid)
        {
            try
            {
                // Size

                if (size.X < HeightfieldColliderShape.MinimumHeightStickWidth || size.Y < HeightfieldColliderShape.MinimumHeightStickLength)
                {
                    throw new ArgumentException($"{ nameof(size) } parameters should be greater than or equal to 2.");
                }

                // HeightScale

                if (MathUtil.IsZero(heightScale))
                {
                    throw new ArgumentException($"{ nameof(heightScale) } is 0.");
                }

                if ((heightType == HeightfieldTypes.Float) && !MathUtil.IsOne(heightScale))
                {
                    throw new ArgumentException($"{ nameof(heightScale) } should be 1 in { heightType } type.");
                }

                // HeightRange

                if (heightRange.Y < heightRange.X)
                {
                    throw new ArgumentException($"{ nameof(heightRange) }.{ nameof(heightRange.Y) } should be greater than { nameof(heightRange.X) }.");
                }

                if (Math.Abs((heightRange.Y / heightScale) - (heightRange.X / heightScale)) < 1)
                {
                    throw new ArgumentException($"{ nameof(heightRange) } is too short.");
                }

View on GitHub (pinned to 96fad776d2)