{"record":{"id":"7b7102172588c467","repo":"stride3d/stride","slug":"nameof-heightrange-is-too-short","errorCode":null,"errorMessage":"{ nameof(heightRange) } is too short.","messagePattern":"(.+?) is too short\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"sources/engine/Stride.Physics/Engine/HeightmapUtils.cs","lineNumber":43,"sourceCode":"                {\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                }\n\n                if ((heightType == HeightfieldTypes.Byte) &&\n                    (Math.Sign(heightRange.X) + Math.Sign(heightRange.Y)) == 0)\n                {\n                    throw new ArgumentException($\"Can't handle { nameof(heightRange) } included both of positive and negative in { heightType } type.\");\n                }\n            }\n            catch (ArgumentException)\n            {\n                if (throwExceptionWhenInvalid) throw;\n\n                return false;\n            }\n\n            return true;\n        }\n","sourceCodeStart":25,"sourceCodeEnd":61,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/engine/Stride.Physics/Engine/HeightmapUtils.cs#L25-L61","documentation":"After ordering, CheckHeightParameters requires the height range span (|Y - X| after dividing by scale) to be at least 1 unit; a span smaller than 1 gives Bullet a degenerate heightfield and throws ArgumentException 'heightRange is too short'.","triggerScenarios":"Calling CheckHeightParameters with a range like (0, 0.5) and scale 1, or a large HeightScale shrinking the effective span below 1 (e.g. range span 10 with scale 100).","commonSituations":"Terrain with nearly flat heights and tight min/max; setting an overly large HeightScale that divides the span down below 1; auto-computed ranges from almost-uniform data.","solutions":["Widen HeightRange so (Y - X) / HeightScale >= 1.","Reduce HeightScale so the effective span reaches at least 1.","Quantize/expand the data range when deriving min/max from heights.","Pre-check with IsValid() and clamp/expand the range automatically."],"exampleFix":"// before\nheightmap.HeightRange = new FloatRange(0f, 0.5f); // span < 1\n// after\nheightmap.HeightRange = new FloatRange(0f, 1f); // span >= 1","handlingStrategy":"validation","validationCode":"if (Math.Abs((range.Y - range.X) / scale) < 1) range = ExpandToMinimumSpan(range, scale);","typeGuard":"bool SpanSufficient(FloatRange r, float scale) => Math.Abs((r.Y - r.X) / scale) >= 1;","tryCatchPattern":"try { CheckHeightParameters(size, type, range, scale, true); } catch (ArgumentException) { /* widen range or reduce scale */ }","preventionTips":["Keep terrain height spans at least 1 unit relative to scale","Avoid very large HeightScale values","Auto-expand degenerate data ranges"],"tags":["csharp","argument-validation","physics","height-range"],"backgroundTag":"value-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"}