{"record":{"id":"a5f6d2e92c8e4ccd","repo":"stride3d/stride","slug":"argumentnullexception-heightstickarray","errorCode":null,"errorMessage":"ArgumentNullException: heightStickArray","messagePattern":"ArgumentNullException: heightStickArray","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"sources/engine/Stride.Physics/FloatHeightStickArraySource.cs","lineNumber":37,"sourceCode":"\n        [DataMember(20)]\n        public Vector2 HeightRange { get; set; } = new Vector2(-10, 10);\n\n        [DataMemberIgnore]\n        public float HeightScale => 1f;\n\n        /// <summary>\n        /// The value to fill the height stick array.\n        /// </summary>\n        [DataMember(30)]\n        public float InitialHeight { get; set; } = 0;\n\n        public bool IsValid() => HeightmapUtils.CheckHeightParameters(HeightStickSize, HeightType, HeightRange, HeightScale, false) &&\n            MathUtil.IsInRange(InitialHeight, HeightRange.X, HeightRange.Y);\n\n        public void CopyTo<T>(UnmanagedArray<T> heightStickArray, int index) where T : struct\n        {\n            if (heightStickArray == null) throw new ArgumentNullException(nameof(heightStickArray));\n            if (heightStickArray is UnmanagedArray<float> unmanagedArray)\n            {\n                unmanagedArray.Fill(InitialHeight, index, HeightStickSize.X * HeightStickSize.Y);\n            }\n            else\n            {\n                throw new NotSupportedException($\"{ typeof(UnmanagedArray<T>) } type is not supported.\");\n            }\n        }\n\n        public bool Match(object obj)\n        {\n            var other = obj as FloatHeightStickArraySource;\n\n            if (other == null)\n            {\n                return false;\n            }","sourceCodeStart":19,"sourceCodeEnd":55,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/engine/Stride.Physics/FloatHeightStickArraySource.cs#L19-L55","documentation":"FloatHeightStickArraySource.CopyTo fills a segment of an unmanaged height array with the initial height. It throws ArgumentNullException when the destination heightStickArray is null, since there is no buffer to fill.","triggerScenarios":"Calling CopyTo on a FloatHeightStickArraySource and passing null as the heightStickArray parameter (typically when the heightstick buffer was never allocated before population).","commonSituations":"Setting up a heightfield collider where the heightstick array allocation was skipped or failed; passing an uninitialized variable from an earlier setup step.","solutions":["Allocate the UnmanagedArray before calling CopyTo.","Check the array for null before calling CopyTo.","Ensure the upstream code that creates the heightstick array actually ran (e.g. HeightmapUtils heightstick setup)."],"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":["Always allocate the UnmanagedArray before population","Size the buffer to HeightStickSize.X * HeightStickSize.Y","Check for null before calling CopyTo"],"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"}