stride3d/stride · error · ArgumentException

parameters should be greater than or equal to 2.

Error message

{ nameof(size) } parameters should be greater than or equal to 2.

What it means

HeightmapUtils.CheckHeightParameters validates heightmap dimensions before building a heightfield collider. Since Bullet heightfields need at least 2x2 points, a size below HeightfieldColliderShape.MinimumHeightStickWidth/Length (2) throws ArgumentException. This fires when throwExceptionWhenInvalid is true (e.g. via the IsValid/exception path from asset validation).

Solutions

  1. Set heightmap.Size to at least (2,2) before validating/creating the collider.
  2. Check that the source image/heightmap import produced the expected resolution.
  3. Call heightmap.IsValid() (non-throwing) to test parameters instead of relying on exceptions.
  4. Regenerate the heightmap data if it was created with default Int2 size.

Example fix

// before
var heightmap = new Heightmap();
heightmap.CheckHeightParameters(true);
// after
var heightmap = new Heightmap();
heightmap.Size = new Int2(64, 64);
heightmap.CheckHeightParameters(true);
Defensive patterns

Strategy: validation

Validate before calling

bool ok = size.X >= 2 && size.Y >= 2;

Type guard

bool ValidSize(Int2 s) => s.X >= HeightfieldColliderShape.MinimumHeightStickWidth && s.Y >= HeightfieldColliderShape.MinimumHeightStickLength;

Try / catch

try { HeightmapUtils.CheckHeightParameters(size, type, range, scale, true); } catch (ArgumentException e) { /* surface validation message */ }

Prevention

When it happens

Trigger: Calling CheckHeightParameters with size.X < 2 or size.Y < 2; creating a HeightfieldColliderShape from a heightmap whose Size Int2 is default(Int2) (0,0) or 1x1.

Common situations: A newly constructed Heightmap whose Size was never set; a heightmap asset imported from an image with fewer than 2 pixels; programmatic heightmap generation passing wrong dimensions.

Related errors


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

Appendix: source

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

// Copyright (c) .NET Foundation and Contributors (https://dotnetfoundation.org/ & https://stride3d.net)
// Distributed under the MIT license. See the LICENSE.md file in the project root for more information.
using System;
using System.Linq;
using Stride.Core.Mathematics;

namespace Stride.Physics
{
    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)
                {

View on GitHub (pinned to 96fad776d2)