{"record":{"id":"7177f679e765d707","repo":"stride3d/stride","slug":"nameof-size-parameters-should-be-greater-than-or-equal-to-2","errorCode":null,"errorMessage":"{ nameof(size) } parameters should be greater than or equal to 2.","messagePattern":"(.+?) parameters should be greater than or equal to 2\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"sources/engine/Stride.Physics/Engine/HeightmapUtils.cs","lineNumber":19,"sourceCode":"// Copyright (c) .NET Foundation and Contributors (https://dotnetfoundation.org/ & https://stride3d.net)\n// Distributed under the MIT license. See the LICENSE.md file in the project root for more information.\nusing System;\nusing System.Linq;\nusing Stride.Core.Mathematics;\n\nnamespace Stride.Physics\n{\n    public class HeightmapUtils\n    {\n        public static bool CheckHeightParameters(Int2 size, HeightfieldTypes heightType, Vector2 heightRange, float heightScale, bool throwExceptionWhenInvalid)\n        {\n            try\n            {\n                // Size\n\n                if (size.X < HeightfieldColliderShape.MinimumHeightStickWidth || size.Y < HeightfieldColliderShape.MinimumHeightStickLength)\n                {\n                    throw new ArgumentException($\"{ nameof(size) } parameters should be greater than or equal to 2.\");\n                }\n\n                // HeightScale\n\n                if (MathUtil.IsZero(heightScale))\n                {\n                    throw new ArgumentException($\"{ nameof(heightScale) } is 0.\");\n                }\n\n                if ((heightType == HeightfieldTypes.Float) && !MathUtil.IsOne(heightScale))\n                {\n                    throw new ArgumentException($\"{ nameof(heightScale) } should be 1 in { heightType } type.\");\n                }\n\n                // HeightRange\n\n                if (heightRange.Y < heightRange.X)\n                {","sourceCodeStart":1,"sourceCodeEnd":37,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/engine/Stride.Physics/Engine/HeightmapUtils.cs#L1-L37","documentation":"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).","triggerScenarios":"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.","commonSituations":"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.","solutions":["Set heightmap.Size to at least (2,2) before validating/creating the collider.","Check that the source image/heightmap import produced the expected resolution.","Call heightmap.IsValid() (non-throwing) to test parameters instead of relying on exceptions.","Regenerate the heightmap data if it was created with default Int2 size."],"exampleFix":"// before\nvar heightmap = new Heightmap();\nheightmap.CheckHeightParameters(true);\n// after\nvar heightmap = new Heightmap();\nheightmap.Size = new Int2(64, 64);\nheightmap.CheckHeightParameters(true);","handlingStrategy":"validation","validationCode":"bool ok = size.X >= 2 && size.Y >= 2;","typeGuard":"bool ValidSize(Int2 s) => s.X >= HeightfieldColliderShape.MinimumHeightStickWidth && s.Y >= HeightfieldColliderShape.MinimumHeightStickLength;","tryCatchPattern":"try { HeightmapUtils.CheckHeightParameters(size, type, range, scale, true); } catch (ArgumentException e) { /* surface validation message */ }","preventionTips":["Initialize Size to real dimensions when constructing Heightmap","Never pass default(Int2)","Prefer IsValid() for non-throwing checks"],"tags":["csharp","argument-validation","physics","heightfield"],"backgroundTag":"argument-out-of-range","analyzedSha":"96fad776d210c221682aac1ccdf4c79dc046fc38","analyzedAt":"2026-09-14T02:59:31.279Z","contentChangedAt":"2026-09-14T02:59:31.279Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}