{"record":{"id":"4395fe1f187bf6c2","repo":"stride3d/stride","slug":"heightstickarray-shortheightstickarraysource","errorCode":null,"errorMessage":"heightStickArray","messagePattern":"heightStickArray","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"sources/engine/Stride.Physics/ShortHeightStickArraySource.cs","lineNumber":47,"sourceCode":"        /// </summary>\n        [DataMember(30)]\n        [NotNull]\n        [Display(\"HeightScale\", Expand = ExpandRule.Always)]\n        public IHeightScaleCalculator HeightScaleCalculator { get; set; } = new HeightScaleCalculator();\n\n        /// <summary>\n        /// The value to fill the height stick array.\n        /// </summary>\n        [DataMember(40)]\n        [DataMemberRange(-32767, 32767, 1, 10, 0)]\n        public short InitialShort { get; set; } = 0;\n\n        public bool IsValid() => HeightmapUtils.CheckHeightParameters(HeightStickSize, HeightType, HeightRange, HeightScale, false) &&\n            MathUtil.IsInRange(InitialShort, -short.MaxValue, short.MaxValue);\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<short> unmanagedArray)\n            {\n                unmanagedArray.Fill(InitialShort, 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 ShortHeightStickArraySource;\n\n            if (other == null)\n            {\n                return false;\n            }","sourceCodeStart":29,"sourceCodeEnd":65,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/engine/Stride.Physics/ShortHeightStickArraySource.cs#L29-L65","documentation":"ShortHeightStickArraySource.CopyTo throws ArgumentNullException named 'heightStickArray' when the destination UnmanagedArray is null. This type fills a pre-allocated unmanaged heightfield buffer with the terrain's initial short height value; a null destination cannot be written to.","triggerScenarios":"Calling CopyTo<T>(UnmanagedArray<T>, int) on a ShortHeightStickArraySource with a null heightStickArray argument — typically when the heightfield buffer failed to allocate or was never created before the copy step (e.g. setting up a HeightfieldColliderShape).","commonSituations":"Terrain/collider setup code where the UnmanagedArray allocation was skipped, wrapped in a using block that already disposed it, or passed through from an uninitialized field; copy/paste setups using the float variant while holding a short-source variable.","solutions":["Allocate the UnmanagedArray before calling CopyTo, sized to HeightStickSize.X * HeightStickSize.Y in the correct element type","Ensure the source array type matches: a ShortHeightStickArraySource requires UnmanagedArray<short> (the generic else branch throws for other types)","Check that the buffer was not disposed before CopyTo runs; keep it alive until the heightfield collider consumes it"],"exampleFix":"// before\nUnmanagedArray<short> sticks = null;\nheightSource.CopyTo(sticks, 0); // ArgumentNullException: heightStickArray\n\n// after\nvar sticks = new UnmanagedArray<short>(heightSource.HeightStickSize.X * heightSource.HeightStickSize.Y);\nheightSource.CopyTo(sticks, 0);","handlingStrategy":"validation","validationCode":"static void EnsureHeightBufferAllocated(UnmanagedArray<short> buffer, Int2 size)\n{\n    if (buffer == null)\n        throw new InvalidOperationException(\"Allocate UnmanagedArray<short> of size \" +\n            (size.X * size.Y) + \" before calling CopyTo\");\n}","typeGuard":"bool IsReadyForCopyTo<T>(ShortHeightStickArraySource src, UnmanagedArray<T> buf) where T : struct =>\n    src != null && src.IsValid() && buf != null && buf is UnmanagedArray<short>;","tryCatchPattern":"try { heightSource.CopyTo(sticks, 0); }\ncatch (ArgumentNullException ex) when (ex.ParamName == \"heightStickArray\")\n{\n    sticks = new UnmanagedArray<short>(heightSource.HeightStickSize.X * heightSource.HeightStickSize.Y);\n    heightSource.CopyTo(sticks, 0);\n}","preventionTips":["Always allocate the destination UnmanagedArray (short type for ShortHeightStickArraySource) before CopyTo","Call IsValid() on the source first to catch configuration problems before allocation","Keep the height buffer alive until the HeightfieldColliderShape is fully constructed (beware of using/dispose scope)","Initialize heightfield buffers in the same place the source is configured so one cannot exist without the other"],"tags":["physics","heightfield","null-argument","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-15T23:17:13.987Z"}