{"record":{"id":"280c5e689cea710c","repo":"stride3d/stride","slug":"argumentnullexception-heightmap","errorCode":null,"errorMessage":"ArgumentNullException: heightmap","messagePattern":"ArgumentNullException: heightmap","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"sources/engine/Stride.Physics/Engine/HeightmapExtensions.cs","lineNumber":15,"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.Annotations;\nusing Stride.Core.Mathematics;\nusing Stride.Graphics;\n\nnamespace Stride.Physics\n{\n    public static class HeightmapExtensions\n    {\n        public static bool IsValid([NotNull] this Heightmap heightmap)\n        {\n            if (heightmap == null) throw new ArgumentNullException(nameof(heightmap));\n\n            bool IsValidHeights()\n            {\n                var length = heightmap.Size.X * heightmap.Size.Y;\n\n                switch (heightmap.HeightType)\n                {\n                    case HeightfieldTypes.Float when heightmap.Floats != null && heightmap.Floats.Length == length:\n                        return true;\n\n                    case HeightfieldTypes.Short when heightmap.Shorts != null && heightmap.Shorts.Length == length:\n                        return true;\n\n                    case HeightfieldTypes.Byte when heightmap.Bytes != null && heightmap.Bytes.Length == length:\n                        return true;\n                }\n\n                return false;","sourceCodeStart":1,"sourceCodeEnd":33,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/engine/Stride.Physics/Engine/HeightmapExtensions.cs#L1-L33","documentation":"The HeightmapExtensions.IsValid extension method validates the heightmap's height data integrity, but first asserts the heightmap instance itself is non-null, throwing ArgumentNullException('heightmap'). Stride uses this fail-fast guard so callers do not silently treat a missing heightmap as 'valid' or 'invalid'.","triggerScenarios":"Calling heightmap.IsValid() where the receiver is null — e.g. the heightmap was never assigned, a terrain component's HeightmapData is null, or an asset failed to load and produced a null reference that was then checked for validity.","commonSituations":"Checking validity of a heightmap loaded from an asset that failed to deserialize; validating optional heightmap data before simulation setup; pipeline code that passes a null heightmap from a failed import.","solutions":["Null-check the Heightmap before calling IsValid: if (heightmap != null && heightmap.IsValid()).","Ensure terrain/asset loading succeeded and the HeightmapData field was populated before validation.","Treat a null heightmap explicitly in game logic (e.g. generate a default flat heightmap) instead of passing null into extension checks.","Wrap the validation call in try-catch for ArgumentNullException when the heightmap source is untrusted."],"exampleFix":"// before\nif (heightmap.IsValid()) { ... } // throws if heightmap is null\n\n// after\nif (heightmap != null && heightmap.IsValid()) { ... }","handlingStrategy":"type-guard","validationCode":"if (heightmap is null) return false; // or handle explicitly before calling IsValid\nreturn heightmap.IsValid();","typeGuard":"bool TryValidate(Heightmap heightmap, out bool isValid)\n{\n    if (heightmap is null) { isValid = false; return false; }\n    isValid = heightmap.IsValid();\n    return true;\n}","tryCatchPattern":"try { valid = heightmap.IsValid(); }\ncatch (ArgumentNullException ex) when (ex.ParamName == \"heightmap\") { valid = false; }","preventionTips":["Null-check the Heightmap receiver before calling extension methods on it.","Ensure terrain assets loaded successfully before validating their heightmaps.","Treat null heightmaps as an explicit 'missing data' case in game logic rather than passing them to validators."],"tags":["physics","heightmap","argument-null","terrain"],"backgroundTag":"null-argument","analyzedSha":"96fad776d210c221682aac1ccdf4c79dc046fc38","analyzedAt":"2026-09-14T02:59:31.279Z","contentChangedAt":"2026-09-14T02:59:31.279Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}