stride3d/stride · error · ArgumentException
is not supported in height type. Or . doesn't match .
Error message
{ typeof(T[]) } is not supported in { heightType } height type. Or { nameof(data) }.{ nameof(data).Length } doesn't match { nameof(size) }. What it means
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.
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.
Example fix
// before var heightmap = Heightmap.Create(size, HeightfieldTypes.Float, range, 1f, intHeights); // int[] unsupported // after var floats = new float[intHeights.Length]; for (int i = 0; i < intHeights.Length; i++) floats[i] = intHeights[i]; var heightmap = Heightmap.Create(size, HeightfieldTypes.Float, range, 1f, floats);
Defensive patterns
Strategy: validation
Validate before calling
var length = size.X * size.Y;
bool ok = (data is float[] f && f.Length == length) || (data is short[] s && s.Length == length) || (data is byte[] b && b.Length == length);
if (!ok) throw new ArgumentException("data must be float[]/short[]/byte[] with Length == size.X * size.Y"); Type guard
bool IsValidHeightData<T>(T[] data, Int2 size) =>
(data is float[] || data is short[] || data is byte[]) && data.Length == size.X * size.Y; Try / catch
try { var hm = Heightmap.Create(size, type, range, scale, data); }
catch (ArgumentException ex) { Logger.Error($"Heightmap data rejected: {ex.Message}"); } Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- ArgumentNullException: data
- ArgumentNullException: heightmap
- ArgumentException
- format is not supported.
- . should be greater than .
AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14).
Data as JSON: /api/errors/8feb837774141f65.
Report an issue: GitHub.
Appendix: source
Thrown at sources/engine/Stride.Physics/Engine/Heightmap.cs:87
/// Used to calculate the height when the height type is Short or Byte. HeightScale should be 1 when the height type is Float.
/// </summary>
[DataMember(70)]
public float HeightScale;
public static Heightmap Create<T>(Int2 size, HeightfieldTypes heightType, Vector2 heightRange, float heightScale, T[] data)
{
if (data == null) throw new ArgumentNullException(nameof(data));
HeightmapUtils.CheckHeightParameters(size, heightType, heightRange, heightScale, true);
var length = size.X * size.Y;
switch (data)
{
case float[] floats when floats.Length == length: break;
case short[] shorts when shorts.Length == length: break;
case byte[] bytes when bytes.Length == length: break;
default: throw new ArgumentException($"{ typeof(T[]) } is not supported in { heightType } height type. Or { nameof(data) }.{ nameof(data).Length } doesn't match { nameof(size) }.");
}
var heightmap = new Heightmap
{
HeightType = heightType,
Size = size,
HeightRange = heightRange,
HeightScale = heightScale,
Floats = data as float[],
Shorts = data as short[],
Bytes = data as byte[],
};
return heightmap;
}
}
}
View on GitHub (pinned to 96fad776d2)