stride3d/stride · error · InvalidOperationException
is a null.
Error message
{ nameof(Heightmap.Bytes) } is a null. What it means
CopyTo<T> on HeightStickArraySourceFromHeightmap requires the source Heightmap to actually hold data in the buffer matching the requested element type T. When T is byte, it reads Heightmap.Bytes; if that array is null it throws InvalidOperationException, because there is no byte data to write into the physics heightstick array.
Solutions
- Ensure the Heightmap is of byte type and its Bytes array is allocated and populated before calling CopyTo<byte>.
- Check Heightmap.HeightType (or which buffer is non-null) and call CopyTo with the matching type parameter (short/byte/float).
- If data comes from an asset, verify it loaded successfully before building the physics heightstick array.
Example fix
// before
var source = new HeightStickArraySourceFromHeightmap { Heightmap = heightmap };
source.CopyTo<byte>(stickArray, 0); // throws if heightmap.Bytes is null
// after
if (heightmap.Bytes == null)
throw new InvalidOperationException("Heightmap byte data must be populated before CopyTo<byte>.");
source.CopyTo<byte>(stickArray, 0); Defensive patterns
Strategy: validation
Validate before calling
if (heightmap.Bytes == null || heightmap.HeightType != HeightfieldTypes.Byte)
throw new InvalidOperationException("Heightmap byte data must be populated before CopyTo<byte>."); Type guard
bool CanCopyAsByte(var h) => h?.Bytes != null;
Prevention
- Always populate the heightmap buffer matching HeightType before creating heightstick arrays.
- Check which of Shorts/Bytes is non-null and pick the CopyTo generic argument from that.
- Validate loaded assets before wiring them into physics.
When it happens
Trigger: Calling CopyTo<byte>(...) on a heightstick source whose Heightmap has HeightfieldTypes byte data not yet allocated, or whose Bytes array was never populated (only Shorts or Floats set).
Common situations: Constructing a Heightmap deserialized from an asset where the byte buffer failed to load; mixing up HeightfieldTypes (heightmap is Short/Float but code copies as byte).
Related errors
- format is not supported.
- . should be greater than .
- height type is not supported.
- Failed to compile .
- failed to scale .. to .. . Check HeightScale and…
AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14).
Data as JSON: /api/errors/731f1887cafda06d.
Report an issue: GitHub.
Appendix: source
Thrown at sources/engine/Stride.Physics/HeightStickArraySourceFromHeightmap.cs:57
var heightStickArrayLength = heightStickArray.Length - index;
if (heightStickArrayLength <= 0) throw new IndexOutOfRangeException(nameof(index));
var typeOfT = typeof(T);
T[] heights;
if (typeOfT == typeof(float))
{
if (Heightmap.Floats == null) throw new InvalidOperationException($"{ nameof(Heightmap.Floats) } is a null.");
heights = (T[])(object)Heightmap.Floats;
}
else if (typeOfT == typeof(short))
{
if (Heightmap.Shorts == null) throw new InvalidOperationException($"{ nameof(Heightmap.Shorts) } is a null.");
heights = (T[])(object)Heightmap.Shorts;
}
else if (typeOfT == typeof(byte))
{
if (Heightmap.Bytes == null) throw new InvalidOperationException($"{ nameof(Heightmap.Bytes) } is a null.");
heights = (T[])(object)Heightmap.Bytes;
}
else
{
throw new NotSupportedException($"{ typeof(UnmanagedArray<T>) } type is not supported.");
}
var heightsLength = heights.Length;
if (heightStickArrayLength < heightsLength) throw new ArgumentException($"{ nameof(heightStickArray) }.{ nameof(heightStickArray.Length) } is not enough to copy.");
heightStickArray.Write(heights, index * Unsafe.SizeOf<T>(), 0, heightsLength);
}
public bool Match(object obj)
{
var other = obj as HeightStickArraySourceFromHeightmap;
if (other == null)View on GitHub (pinned to 96fad776d2)