{"record":{"id":"a39614aa22dc2936","repo":"stride3d/stride","slug":"argumentnullexception-heightstickarray-a39614","errorCode":null,"errorMessage":"ArgumentNullException: heightStickArray","messagePattern":"ArgumentNullException: heightStickArray","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"sources/engine/Stride.Physics/HeightStickArraySourceFromHeightmap.cs","lineNumber":37,"sourceCode":"\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            }\n            else if (typeOfT == typeof(byte))","sourceCodeStart":19,"sourceCodeEnd":55,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/engine/Stride.Physics/HeightStickArraySourceFromHeightmap.cs#L19-L55","documentation":"A validation guard in HeightStickArraySourceFromHeightmap.CopyTo: the destination heightStickArray (the UnmanagedArray the heightmap data is copied into) is invalid/null — the guard fires when the source Heightmap is null or the target array is null. Copying heightfield data into the physics height stick requires both a valid heightmap source and a valid target buffer; either missing triggers ArgumentNullException named 'heightStickArray'.","triggerScenarios":"Calling CopyTo with a null UnmanagedArray destination, typically when the heightstick buffer was never allocated for the heightfield.","commonSituations":"Heightfield collider setup where buffer allocation was skipped; passing an uninitialized variable from a failed earlier setup step.","solutions":["Allocate the UnmanagedArray (sized to HeightStickSize.X * HeightStickSize.Y) before calling CopyTo.","Check the array for null before calling CopyTo.","Verify the heightfield heightstick allocation step ran successfully."],"exampleFix":"// before\nsource.CopyTo(heightStickArray, 0); // throws if null\n// after\nheightStickArray ??= new UnmanagedArray<float>(size.X * size.Y);\nsource.CopyTo(heightStickArray, 0);","handlingStrategy":"validation","validationCode":"if (heightStickArray == null)\n    throw new InvalidOperationException(\"Allocate heightstick array before CopyTo\");","typeGuard":null,"tryCatchPattern":"try { source.CopyTo(heightStickArray, 0); }\ncatch (ArgumentNullException ex) { /* allocate the buffer and retry */ }","preventionTips":["Allocate the buffer sized HeightStickSize.X * HeightStickSize.Y before copying","Check for null before calling CopyTo","Verify the heightfield allocation step succeeded"],"tags":["physics","heightfield","null-argument"],"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"}