stride3d/stride · error · NotSupportedException

type is not supported.

Error message

{ typeof(UnmanagedArray<T>) } type is not supported.

What it means

CopyTo<T> only supports T of short or byte, matching the buffers stored on Heightmap (Shorts/Bytes). Any other T (e.g. float, int, UnmanagedArray<T>) falls into the else branch and throws NotSupportedException, because the engine's heightstick array only accepts those element types.

Solutions

  1. Call CopyTo<short> or CopyTo<byte> to match the Heightmap's stored buffer type.
  2. If height data is float, quantize it to short or byte (apply HeightScale/HeightOffset) and store in Heightmap.Shorts/Bytes first.
  3. Inspect Heightmap.HeightType and dispatch the CopyTo generic argument accordingly.

Example fix

// before
source.CopyTo<float>(stickArray, 0); // NotSupportedException
// after
source.CopyTo<short>(stickArray, 0); // matches heightmap.HeightType == HeightfieldTypes.Short
Defensive patterns

Strategy: type-guard

Validate before calling

if (typeof(T) != typeof(short) && typeof(T) != typeof(byte))
    throw new InvalidOperationException("CopyTo only supports short or byte.");

Type guard

bool IsSupportedHeightType<T>() => typeof(T) == typeof(short) || typeof(T) == typeof(byte);

Try / catch

try { source.CopyTo<T>(stickArray, index); }
catch (NotSupportedException) { /* fall back to short/byte conversion */ }

Prevention

When it happens

Trigger: Calling heightStickArraySource.CopyTo<float>(...) or CopyTo<int>(...) — any generic argument other than short or byte.

Common situations: Developers assume float heightmaps are supported (Bullet heightfields are short/byte) and pass the float array type directly.

Understand the failure class

Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.

Related errors


AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14). Data as JSON: /api/errors/ffee76f61bb52db9. Report an issue: GitHub.

Appendix: source

Thrown at sources/engine/Stride.Physics/HeightStickArraySourceFromHeightmap.cs:62

            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)
            {
                return false;
            }

            return other.Heightmap == Heightmap;

View on GitHub (pinned to 96fad776d2)