{"record":{"id":"8feb837774141f65","repo":"stride3d/stride","slug":"typeof-t-is-not-supported-in-heighttype-height-type-or","errorCode":null,"errorMessage":"{ typeof(T[]) } is not supported in { heightType } height type. Or { nameof(data) }.{ nameof(data).Length } doesn't match { nameof(size) }.","messagePattern":"(.+?) is not supported in (.+?) height type\\. Or (.+?)\\.(.+?) doesn't match (.+?)\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"sources/engine/Stride.Physics/Engine/Heightmap.cs","lineNumber":87,"sourceCode":"        /// Used to calculate the height when the height type is Short or Byte. HeightScale should be 1 when the height type is Float.\n        /// </summary>\n        [DataMember(70)]\n        public float HeightScale;\n\n        public static Heightmap Create<T>(Int2 size, HeightfieldTypes heightType, Vector2 heightRange, float heightScale, T[] data)\n        {\n            if (data == null) throw new ArgumentNullException(nameof(data));\n\n            HeightmapUtils.CheckHeightParameters(size, heightType, heightRange, heightScale, true);\n\n            var length = size.X * size.Y;\n\n            switch (data)\n            {\n                case float[] floats when floats.Length == length: break;\n                case short[] shorts when shorts.Length == length: break;\n                case byte[] bytes when bytes.Length == length: break;\n                default: throw new ArgumentException($\"{ typeof(T[]) } is not supported in { heightType } height type. Or { nameof(data) }.{ nameof(data).Length } doesn't match { nameof(size) }.\");\n            }\n\n            var heightmap = new Heightmap\n            {\n                HeightType = heightType,\n                Size = size,\n                HeightRange = heightRange,\n                HeightScale = heightScale,\n                Floats = data as float[],\n                Shorts = data as short[],\n                Bytes = data as byte[],\n            };\n\n            return heightmap;\n        }\n    }\n}\n","sourceCodeStart":69,"sourceCodeEnd":105,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/engine/Stride.Physics/Engine/Heightmap.cs#L69-L105","documentation":"Heightmap.Create validates that the data array's element type is one of float[], short[], or byte[] AND that its length equals size.X * size.Y. If either check fails (unsupported element type for the heightfield type, or length mismatch with the declared size), it throws ArgumentException.","triggerScenarios":"Calling Heightmap.Create<T> with a T[] that is not float[], short[], or byte[] (e.g. int[] or double[]), or with a supported array type whose Length does not equal size.X * size.Y.","commonSituations":"Passing int[] height data from image processing code; computing size after resizing the array so lengths diverge; using a padded array (row stride/pitch) whose length exceeds X*Y; switching heightfield types between 8/16/32-bit without converting the array.","solutions":["Match the array type to HeightfieldTypes: float[] for Float, short[] for Short, byte[] for Byte — convert the data accordingly.","Ensure data.Length == size.X * size.Y exactly; trim padding or compute size from the array.","Verify HeightfieldTypes corresponds to the actual element type T before calling Create.","For row-pitched data (e.g. PNG stride), copy row-by-row into a tightly packed array first."],"exampleFix":"// before\nvar heightmap = Heightmap.Create(size, HeightfieldTypes.Float, range, 1f, intHeights); // int[] unsupported\n\n// after\nvar floats = new float[intHeights.Length];\nfor (int i = 0; i < intHeights.Length; i++) floats[i] = intHeights[i];\nvar heightmap = Heightmap.Create(size, HeightfieldTypes.Float, range, 1f, floats);","handlingStrategy":"validation","validationCode":"var length = size.X * size.Y;\nbool ok = (data is float[] f && f.Length == length) || (data is short[] s && s.Length == length) || (data is byte[] b && b.Length == length);\nif (!ok) throw new ArgumentException(\"data must be float[]/short[]/byte[] with Length == size.X * size.Y\");","typeGuard":"bool IsValidHeightData<T>(T[] data, Int2 size) =>\n    (data is float[] || data is short[] || data is byte[]) && data.Length == size.X * size.Y;","tryCatchPattern":"try { var hm = Heightmap.Create(size, type, range, scale, data); }\ncatch (ArgumentException ex) { Logger.Error($\"Heightmap data rejected: {ex.Message}\"); }","preventionTips":["Match the array element type to HeightfieldTypes (float/short/byte).","Ensure data.Length equals size.X * size.Y exactly — strip row padding/pitch beforehand.","Convert other numeric types (int, double) to the matching element type before calling Create.","Compute size from the array when the source is unknown rather than passing mismatched values."],"tags":["physics","heightmap","argument","terrain","array"],"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"}