{"record":{"id":"62df1c7a9c8200a4","repo":"stride3d/stride","slug":"nameof-scaletoheightrange-failed-to-scale-mint-maxt-to-min","errorCode":null,"errorMessage":"{ nameof(ScaleToHeightRange) } failed to scale { minT }..{ maxT } to { min }..{ max }. Check HeightScale and HeightRange are proper.","messagePattern":"(.+?) failed to scale (.+?)\\.\\.(.+?) to (.+?)\\.\\.(.+?)\\. Check HeightScale and HeightRange are proper\\.","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"sources/engine/Stride.Assets/Physics/HeightmapAssetCompiler.cs","lineNumber":309,"sourceCode":"            {\n                float min;\n                float max;\n\n                var typeOfT = typeof(T);\n\n                if (typeOfT == typeof(float))\n                {\n                    min = heightRange.X;\n                    max = heightRange.Y;\n                }\n                else if (typeOfT == typeof(short) || typeOfT == typeof(byte))\n                {\n                    CalculateByteOrShortRange(heightRange, heightScale, out min, out max);\n\n                    if (!MathUtil.IsInRange(min, minT, maxT) ||\n                        !MathUtil.IsInRange(max, minT, maxT))\n                    {\n                        throw new Exception(\n                            $\"{ nameof(ScaleToHeightRange) } failed to scale { minT }..{ maxT } to { min }..{ max }. Check HeightScale and HeightRange are proper.\");\n                    }\n                }\n                else\n                {\n                    throw new NotSupportedException($\"{ typeof(T[]) } type is not supported.\");\n                }\n\n                commandContext?.Logger.Info($\"[{Url}] ScaleToHeightRange : { minT }..{ maxT } -> { min }..{ max }\");\n\n                if (typeOfT == typeof(float))\n                {\n                    float[] floats = heights as float[];\n                    for (var i = 0; i < floats.Length; ++i)\n                    {\n                        floats[i] = MathUtil.Clamp(MathUtil.Lerp(min, max, MathUtil.InverseLerp(minT, maxT, floats[i])), min, max);\n                    }\n                }","sourceCodeStart":291,"sourceCodeEnd":327,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/engine/Stride.Assets/Physics/HeightmapAssetCompiler.cs#L291-L327","documentation":"ScaleToHeightRange<T> computes the target byte/short range from HeightRange and HeightScale via CalculateByteOrShortRange, then verifies those target bounds lie inside the source data's actual min/max (minT..maxT). If the requested range falls outside what the data can represent, it throws, advising you to check HeightScale and HeightRange.","triggerScenarios":"Scaling a float heightmap to a byte/short range where CalculateByteOrShortRange yields min/max outside the actual data range (minT..maxT) — e.g. HeightScale too large, or HeightRange values beyond what the quantized type can express from the data.","commonSituations":"HeightScale set inconsistently with the mesh's actual height extent, HeightRange manual values not matching the terrain's real min/max heights, or float source data spanning far beyond the intended byte/short bounds.","solutions":["Set HeightRange to the terrain's actual min/max heights (visible in the log line minT..maxT)","Reduce HeightScale so CalculateByteOrShortRange stays within the source data range","Disable ScaleToHeightRange if the data already fits the target type","Recompute terrain bounds and update the heightmap asset accordingly"],"exampleFix":"// before\nheightmapAsset.HeightScale = 1000f;   // pushes target range outside data\nheightmapAsset.HeightRange = new Vector2(0f, 50000f);\n// after\nheightmapAsset.HeightScale = 1f;\nheightmapAsset.HeightRange = new Vector2(0f, 120f); // matches actual terrain","handlingStrategy":"validation","validationCode":"var (minT, maxT) = GetActualDataRange(floatHeights);\nvar scaledMin = heightRange.X / heightScale;\nvar scaledMax = heightRange.Y / heightScale;\nif (scaledMin < minT || scaledMax > maxT)\n    throw new InvalidOperationException($\"HeightRange/HeightScale out of data range {minT}..{maxT}\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Read minT..maxT from the build log and set HeightRange to match","Keep HeightScale consistent with the terrain's actual height extent","Disable ScaleToHeightRange when the source data already fits","Recompute terrain bounds after terrain edits"],"tags":["physics","heightmap","value-out-of-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"}