stride3d/stride · error · ArgumentException

. should be greater than .

Error message

{ nameof(heightRange) }.{ nameof(heightRange.Y) } should be greater than { nameof(heightRange.X) }.

What it means

CheckHeightParameters requires heightRange.Y (max) to be strictly greater than heightRange.X (min); an inverted or empty range cannot map heights and throws ArgumentException. It is thrown before the too-short check, so this is the first range error hit.

Solutions

  1. Order the range so HeightRange.X is the minimum and Y the maximum.
  2. Compute the range from data: X = min(heights), Y = max(heights).
  3. Validate with heightmap.IsValid() before collider creation.
  4. Add an editor/runtime assertion that range.Y > range.X when the heightmap is configured.

Example fix

// before
heightmap.HeightRange = new FloatRange(10f, -10f);
// after
heightmap.HeightRange = new FloatRange(-10f, 10f); // X = min, Y = max
Defensive patterns

Strategy: validation

Validate before calling

if (range.Y <= range.X) range = new FloatRange(range.Y, range.X); // or reject

Type guard

bool ValidRange(FloatRange r) => r.Y > r.X;

Try / catch

try { CheckHeightParameters(size, type, range, scale, true); } catch (ArgumentException) { /* recompute min/max from data */ }

Prevention

When it happens

Trigger: Passing a HeightRange where Max < Min, e.g. new HeightRange(10, -10), or a range whose X and Y are swapped after editing.

Common situations: Manual range entry in the editor with swapped min/max; computing range from data with Mathf.Min/Max results assigned to the wrong fields; copying ranges between heightmaps of opposite orientation.

Understand the failure class

Background: "value must be between 0 and 1" / "out of range" / "must not be negative" errors: fixing range-validation failures across open-source libraries — this error's family across 42 libraries.

Related errors


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

Appendix: source

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

                }

                // 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.");
                }

                if ((heightType == HeightfieldTypes.Byte) &&
                    (Math.Sign(heightRange.X) + Math.Sign(heightRange.Y)) == 0)
                {
                    throw new ArgumentException($"Can't handle { nameof(heightRange) } included both of positive and negative in { heightType } type.");
                }
            }
            catch (ArgumentException)
            {
                if (throwExceptionWhenInvalid) throw;

                return false;

View on GitHub (pinned to 96fad776d2)