{"record":{"id":"a7b26920c03c1750","repo":"OpenRA/OpenRA","slug":"terrainsmoothing-must-be-between-0-and-matrixutil","errorCode":null,"errorMessage":"TerrainSmoothing must be between 0 and {MatrixUtils.MaxBinomialKernelRadius} inclusive","messagePattern":"TerrainSmoothing must be between 0 and (.+?) inclusive","errorType":"exception","errorClass":"MapGenerationException","httpStatus":null,"severity":"error","filePath":"OpenRA.Mods.Common/Traits/World/ClassicMapGenerator.cs","lineNumber":311,"sourceCode":"\t\t\t\t\t\telse\n\t\t\t\t\t\t\tthrow new YamlException($\"Invalid resource spawn weight `{subMy.Value}`\");\n\t\t\t\t\t});\n\t\t\t}\n\n\t\t\tpublic void Validate(ITemplatedTerrainInfo terrainInfo)\n\t\t\t{\n\t\t\t\tif (Rotations < 1)\n\t\t\t\t\tthrow new MapGenerationException(\"Rotations must be >= 1\");\n\t\t\t\tif (TerrainFeatureSize < 1)\n\t\t\t\t\tthrow new MapGenerationException(\"TerrainFeatureSize must be >= 1\");\n\t\t\t\tif (ForestFeatureSize < 1)\n\t\t\t\t\tthrow new MapGenerationException(\"ForestFeatureSize must be >= 1\");\n\t\t\t\tif (ResourceFeatureSize < 1)\n\t\t\t\t\tthrow new MapGenerationException(\"ResourceFeatureSize must be >= 1\");\n\t\t\t\tif (CivilianBuildingsFeatureSize < 1)\n\t\t\t\t\tthrow new MapGenerationException(\"CivilianBuildingsFeatureSize must be >= 1\");\n\t\t\t\tif (TerrainSmoothing < 0 || TerrainSmoothing > MatrixUtils.MaxBinomialKernelRadius)\n\t\t\t\t\tthrow new MapGenerationException($\"TerrainSmoothing must be between 0 and {MatrixUtils.MaxBinomialKernelRadius} inclusive\");\n\t\t\t\tif (WaterRoughness > 0 && MinimumCoastStraight < 0)\n\t\t\t\t\tthrow new MapGenerationException(\"MinimumCoastStraight must be >= 0\");\n\t\t\t\tif (SmoothingThreshold < (FractionMax + 1) / 2 || SmoothingThreshold > FractionMax)\n\t\t\t\t\tthrow new MapGenerationException($\"SmoothingThreshold must be between {(FractionMax + 1) / 2} and {FractionMax} inclusive\");\n\t\t\t\tif (MinimumLandSeaThickness < 1)\n\t\t\t\t\tthrow new MapGenerationException(\"MinimumLandSeaThickness must be >= 1\");\n\t\t\t\tif (MinimumMountainThickness < 1)\n\t\t\t\t\tthrow new MapGenerationException(\"MinimumMountainThickness must be >= 1\");\n\t\t\t\tif (Water < 0 || Water > FractionMax)\n\t\t\t\t\tthrow new MapGenerationException($\"Water must be between 0 and {FractionMax} inclusive\");\n\t\t\t\tif (Forests < 0 || Forests > FractionMax)\n\t\t\t\t\tthrow new MapGenerationException($\"Forest must be between 0 and {FractionMax} inclusive\");\n\t\t\t\tif (ForestCutout < 0)\n\t\t\t\t\tthrow new MapGenerationException(\"ForestCutout must be >= 0\");\n\t\t\t\tif (MaximumCutoutSpacing < 0)\n\t\t\t\t\tthrow new MapGenerationException(\"TopologyAugmentationThreshold must be >= 0\");\n\t\t\t\tif (ForestClumpiness < 0)\n\t\t\t\t\tthrow new MapGenerationException(\"ForestClumpiness must be >= 0\");","sourceCodeStart":293,"sourceCodeEnd":329,"githubUrl":"https://github.com/OpenRA/OpenRA/blob/a520984d91eda9de48a62b1d15c1e3bad0d4fb1a/OpenRA.Mods.Common/Traits/World/ClassicMapGenerator.cs#L293-L329","documentation":"Validate() checks that TerrainSmoothing is between 0 and MatrixUtils.MaxBinomialKernelRadius (constant value 10) inclusive. TerrainSmoothing controls the radius of a binomial blur kernel applied to the elevation noise. Values outside [0,10] exceed the precomputed kernel table in MatrixUtils, which would cause an ArgumentException downstream in BinomialBlur. The field defaults to 0 and is [FieldLoader.Require].","triggerScenarios":"The TerrainSmoothing key is set to a negative number or a value greater than 10 in the generator YAML.","commonSituations":"Mod developer sets a large smoothing value (e.g. 20) expecting more blur, not knowing the kernel table is capped at radius 10. Negative value entered accidentally. Version upgrade where MaxBinomialKernelRadius was reduced.","solutions":["Set TerrainSmoothing to an integer in the range 0–10","Use 0 for no smoothing, 10 for maximum available smoothing","Check MatrixUtils.MaxBinomialKernelRadius in your OpenRA version to confirm the upper bound"],"exampleFix":"# before\nTerrainSmoothing: 20\n# after\nTerrainSmoothing: 10","handlingStrategy":"validation","validationCode":"// Pre-flight check: TerrainSmoothing must be in [0, MaxBinomialKernelRadius]\nstatic void ValidateTerrainSmoothing(int smoothing)\n{\n    if (smoothing < 0 || smoothing > MatrixUtils.MaxBinomialKernelRadius)\n        throw new ArgumentOutOfRangeException(nameof(smoothing),\n            $\"ClassicMapGenerator TerrainSmoothing must be between 0 and {MatrixUtils.MaxBinomialKernelRadius} inclusive\");\n}","typeGuard":"static bool IsValidTerrainSmoothing(int value) =>\n    value >= 0 && value <= MatrixUtils.MaxBinomialKernelRadius;","tryCatchPattern":"try\n{\n    var param = new Parameters(map, yaml);\n}\ncatch (MapGenerationException ex) when (ex.Message.Contains(\"TerrainSmoothing must be between\"))\n{\n    Console.Error.WriteLine($\"Invalid TerrainSmoothing: {ex.Message}\");\n    // clamp to valid range or abort\n}","preventionTips":["TerrainSmoothing is a binomial blur kernel radius, capped at 10 by the MatrixUtils kernel table","Check MatrixUtils.MaxBinomialKernelRadius in your OpenRA version if you upgrade","Start with a moderate value like 3–5 and adjust visually"],"tags":["openra","map-generator","config-validation","terrain","smoothing","kernel-radius"],"backgroundTag":null,"analyzedSha":"a520984d91eda9de48a62b1d15c1e3bad0d4fb1a","analyzedAt":"2026-08-13T15:30:14.787Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}