{"record":{"id":"95f9dda292c77473","repo":"stride3d/stride","slug":"nameof-heightscale-is-0","errorCode":null,"errorMessage":"{ nameof(heightScale) } is 0.","messagePattern":"\\{ nameof\\(heightScale\\) \\} is 0\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"sources/engine/Stride.Physics/Engine/HeightmapUtils.cs","lineNumber":26,"sourceCode":"{\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                {\n                    throw new ArgumentException($\"{ nameof(heightRange) }.{ nameof(heightRange.Y) } should be greater than { nameof(heightRange.X) }.\");\n                }\n\n                if (Math.Abs((heightRange.Y / heightScale) - (heightRange.X / heightScale)) < 1)\n                {\n                    throw new ArgumentException($\"{ nameof(heightRange) } is too short.\");\n                }","sourceCodeStart":8,"sourceCodeEnd":44,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/engine/Stride.Physics/Engine/HeightmapUtils.cs#L8-L44","documentation":"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.","triggerScenarios":"Calling CheckHeightParameters with heightScale == 0; a Heightmap whose HeightScale property was never set and defaults to 0.","commonSituations":"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.","solutions":["Set HeightScale to a nonzero value appropriate for your terrain (e.g. 1).","If heights are already in final units, set HeightScale to 1 (required for Float type anyway).","Validate with heightmap.IsValid() before constructing the collider.","Fix pipeline code that computes scale so it cannot produce 0 (guard division)."],"exampleFix":"// before\nheightmap.HeightScale = 0;\nheightmap.CheckHeightParameters(true);\n// after\nheightmap.HeightScale = 1.0f;\nheightmap.CheckHeightParameters(true);","handlingStrategy":"validation","validationCode":"if (MathUtil.IsZero(heightScale)) heightScale = 1f;","typeGuard":"bool ValidScale(float s) => !MathUtil.IsZero(s);","tryCatchPattern":"try { CheckHeightParameters(size, type, range, scale, true); } catch (ArgumentException) { /* prompt for a nonzero scale */ }","preventionTips":["Always set HeightScale explicitly (1 for Float)","Guard computed scales against 0","Validate with IsValid() before collider creation"],"tags":["csharp","argument-validation","physics","heightscale"],"backgroundTag":"invalid-argument-value","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"}