{"record":{"id":"82fab89cc01efe11","repo":"stride3d/stride","slug":"nameof-heightstickarray-nameof-heightstickarray-length-is","errorCode":null,"errorMessage":"{ nameof(heightStickArray) }.{ nameof(heightStickArray.Length) } is not enough to copy.","messagePattern":"(.+?)\\.(.+?) is not enough to copy\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"sources/engine/Stride.Physics/HeightStickArraySourceFromHeightmap.cs","lineNumber":66,"sourceCode":"                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))\n            {\n                if (Heightmap.Bytes == null) throw new InvalidOperationException($\"{ nameof(Heightmap.Bytes) } is a null.\");\n                heights = (T[])(object)Heightmap.Bytes;\n            }\n            else\n            {\n                throw new NotSupportedException($\"{ typeof(UnmanagedArray<T>) } type is not supported.\");\n            }\n\n            var heightsLength = heights.Length;\n            if (heightStickArrayLength < heightsLength) throw new ArgumentException($\"{ nameof(heightStickArray) }.{ nameof(heightStickArray.Length) } is not enough to copy.\");\n\n            heightStickArray.Write(heights, index * Unsafe.SizeOf<T>(), 0, heightsLength);\n        }\n\n        public bool Match(object obj)\n        {\n            var other = obj as HeightStickArraySourceFromHeightmap;\n\n            if (other == null)\n            {\n                return false;\n            }\n\n            return other.Heightmap == Heightmap;\n        }\n    }\n}\n","sourceCodeStart":48,"sourceCodeEnd":84,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/engine/Stride.Physics/HeightStickArraySourceFromHeightmap.cs#L48-L84","documentation":"After selecting the heights buffer, CopyTo verifies the destination heightstick array is at least as long as the source heights array. If heightStickArrayLength < heights.Length it throws ArgumentException: the destination cannot hold all height samples, so the copy would overflow.","triggerScenarios":"Calling CopyTo with a heightstick array sized for a smaller terrain grid than the Heightmap provides, e.g. heightmap 256x256 but stick array sized 128x128.","commonSituations":"Mismatch between terrain asset resolution and the physics HeightStickArrayDescription dimensions; forgetting that length includes both X and Z sample counts multiplied.","solutions":["Size the HeightStickArrayDescription (width/length of samples) to match the Heightmap dimensions exactly.","Compute the stick array length as numRows * numColumns matching the heights array length before calling CopyTo.","Crop or resample the Heightmap data to fit the allocated stick array."],"exampleFix":"// before\nvar desc = new HeightStickArrayDescription(128, 128); // too small\nsource.CopyTo<short>(stickArray, 0); // ArgumentException\n// after\nvar desc = new HeightStickArrayDescription(heightmap.Height, heightmap.Width); // matches source\nsource.CopyTo<short>(stickArray, 0);","handlingStrategy":"validation","validationCode":"if (stickArrayLength < heights.Length)\n    throw new InvalidOperationException(\"HeightStickArray too small for heightmap data.\");","typeGuard":null,"tryCatchPattern":"try { source.CopyTo<short>(stickArray, 0); }\ncatch (ArgumentException e) { Console.WriteLine($\"Resize stick array: {e.Message}\"); }","preventionTips":["Derive HeightStickArrayDescription dimensions from the heightmap, not hard-coded constants.","Assert stickArray length == heightmap.Width * heightmap.Height in debug builds.","Resample terrain assets when changing physics resolution."],"tags":["physics","argument","buffer-size"],"backgroundTag":"invalid-argument-value","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"}