BabylonJS/Babylon.js · error

Unsupported buffer type

Error message

Unsupported buffer type

What it means

When createTexture is called with fromData and a buffer, the engine accepts only ArrayBuffer, ArrayBufferView (typed arrays), or base64/data-URI strings. Any other buffer value (e.g. a plain object, Blob, or number) reaches the else branch and throws 'Unsupported buffer type'.

Source

Thrown at packages/dev/core/src/Engines/thinNativeEngine.pure.ts:2085

                        texture.onLoadedObservable.notifyObservers(texture);
                        texture.onLoadedObservable.clear();
                    },
                    () => {
                        throw new Error("Could not load a native texture.");
                    }
                );
            };

            if (fromData && buffer) {
                if (buffer instanceof ArrayBuffer) {
                    onload(new Uint8Array(buffer));
                } else if (ArrayBuffer.isView(buffer)) {
                    onload(buffer);
                } else if (typeof buffer === "string") {
                    onload(new Uint8Array(DecodeBase64UrlToBinary(buffer)));
                } else {
                    throw new Error("Unsupported buffer type");
                }
            } else {
                if (isBase64) {
                    onload(new Uint8Array(DecodeBase64UrlToBinary(url)));
                } else {
                    this._loadFile(
                        url,
                        (data) => onload(new Uint8Array(data as ArrayBuffer)),
                        undefined,
                        undefined,
                        true,
                        (request?: IWebRequest, exception?: any) => {
                            onInternalError("Unable to load " + (request ? request.responseURL : url, exception));
                        }
                    );
                }
            }
        }

View on GitHub (pinned to 0592b347b8)

Solutions

  1. Convert the value to a typed array first: new Uint8Array(await blob.arrayBuffer()).
  2. If it is a string, ensure it is a base64 or data: URL string, not an http URL.
  3. If it is raw pixel data, wrap it: onload(new Uint8Array(rawBytes)) equivalent before calling createTexture.

Example fix

// before
engine.createTexture("", false, false, scene, 3, ok, err, blob, null, -1, "", "", null, true);

// after
const bytes = new Uint8Array(await blob.arrayBuffer());
engine.createTexture("", false, false, scene, 3, ok, err, bytes, null, -1, "", "", null, true);
Defensive patterns

Strategy: type-guard

Validate before calling

if (!(buffer instanceof ArrayBuffer) && !ArrayBuffer.isView(buffer) && !(typeof buffer === "string" && (buffer.startsWith("data:") || /^[A-Za-z0-9+/=]+$/.test(buffer)))) {
  throw new TypeError("createTexture buffer must be ArrayBuffer, typed array, or base64 string");
}

Type guard

const isNativeTextureBuffer = (b: unknown): b is ArrayBuffer | ArrayBufferView | string =>
  b instanceof ArrayBuffer || ArrayBuffer.isView(b as object) || typeof b === "string";

Try / catch

try {
  engine.createTexture("", false, false, scene, 3, onLoad, onError, buffer, null, -1, "", "", null, true);
} catch (e) {
  if (e.message === "Unsupported buffer type") {
    const bytes = new Uint8Array(await toArrayBuffer(buffer));
    engine.createTexture("", false, false, scene, 3, onLoad, onError, bytes, null, -1, "", "", null, true);
  } else throw e;
}

Prevention

When it happens

Trigger: Passing createTexture(url, noMip, invertY, scene, mode, onLoad, onError, buffer, ..., format, ext, mime, opts, fromData=true) where buffer is not ArrayBuffer, an ArrayBufferView, nor a base64 string.

Common situations: Passing a Blob, File, ImageBitmap, or a plain string URL as the buffer with fromData=true; misremembering that Blob/ImageBitmap are only handled in other code paths.

Related errors


AI-assisted analysis of BabylonJS/Babylon.js@0592b347b8 (2026-08-30). Data as JSON: /api/errors/c4006b5e3cd09523. Report an issue: GitHub.