{"record":{"id":"3d37068938be2419","repo":"stride3d/stride","slug":"nameof-heightmap-is-a-null","errorCode":null,"errorMessage":"{ nameof(Heightmap) } is a null","messagePattern":"(.+?) is a null","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"sources/engine/Stride.Physics/HeightStickArraySourceFromHeightmap.cs","lineNumber":36,"sourceCode":"        public Heightmap Heightmap { get; set; }\n\n        [DataMemberIgnore]\n        public HeightfieldTypes HeightType => Heightmap?.HeightType ?? default;\n\n        [DataMemberIgnore]\n        public Int2 HeightStickSize => Heightmap?.Size ?? default;\n\n        [DataMemberIgnore]\n        public Vector2 HeightRange => Heightmap?.HeightRange ?? default;\n\n        [DataMemberIgnore]\n        public float HeightScale => Heightmap?.HeightScale ?? default;\n\n        public bool IsValid() => Heightmap?.IsValid() ?? false;\n\n        public void CopyTo<T>(UnmanagedArray<T> heightStickArray, int index) where T : struct\n        {\n            if (Heightmap == null) throw new InvalidOperationException($\"{ nameof(Heightmap) } is a null\");\n            if (heightStickArray == null) throw new ArgumentNullException(nameof(heightStickArray));\n\n            var heightStickArrayLength = heightStickArray.Length - index;\n            if (heightStickArrayLength <= 0) throw new IndexOutOfRangeException(nameof(index));\n\n            var typeOfT = typeof(T);\n            T[] heights;\n\n            if (typeOfT == typeof(float))\n            {\n                if (Heightmap.Floats == null) throw new InvalidOperationException($\"{ nameof(Heightmap.Floats) } is a null.\");\n                heights = (T[])(object)Heightmap.Floats;\n            }\n            else if (typeOfT == typeof(short))\n            {\n                if (Heightmap.Shorts == null) throw new InvalidOperationException($\"{ nameof(Heightmap.Shorts) } is a null.\");\n                heights = (T[])(object)Heightmap.Shorts;\n            }","sourceCodeStart":18,"sourceCodeEnd":54,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/engine/Stride.Physics/HeightStickArraySourceFromHeightmap.cs#L18-L54","documentation":"HeightStickArraySourceFromHeightmap.CopyTo copies heightmap data into a heightstick array. It first requires the Heightmap reference to be non-null; otherwise it throws InvalidOperationException, since no height data exists to copy.","triggerScenarios":"Calling CopyTo when the Heightmap property was never assigned (or was set to null), e.g. a heightfield collider component referencing a heightmap asset that is null/not loaded.","commonSituations":"A HeightfieldColliderShape asset whose heightmap field is empty; heightmap asset failed to load or was removed from the content project; deserializing a scene with a missing heightmap reference.","solutions":["Assign a valid heightmap to the source before calling CopyTo.","Check IsValid() (which returns false when Heightmap is null or invalid) before copying.","Fix the missing/broken heightmap asset reference in the collider/scene asset.","Load the heightmap asset before building the heightfield collider."],"exampleFix":"// before\nheightmapSource.CopyTo(heightStickArray, 0); // throws if Heightmap null\n// after\nif (heightmapSource.IsValid())\n    heightmapSource.CopyTo(heightStickArray, 0);","handlingStrategy":"validation","validationCode":"if (!heightmapSource.IsValid())\n    return; // Heightmap null or invalid","typeGuard":null,"tryCatchPattern":"try { heightmapSource.CopyTo(heightStickArray, 0); }\ncatch (InvalidOperationException ex) { /* heightmap not assigned; fix asset reference */ }","preventionTips":["Check IsValid() before copying","Ensure heightmap assets are assigned in collider assets","Verify asset references survive scene serialization"],"tags":["physics","heightfield","null-reference"],"backgroundTag":"null-argument","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"}