{"record":{"id":"126d12b03b2e5413","repo":"BabylonJS/Babylon.js","slug":"unsupported-data-for-createimagebitmap","errorCode":null,"errorMessage":"Unsupported data for createImageBitmap.","messagePattern":"Unsupported data for createImageBitmap\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/dev/core/src/Engines/thinNativeEngine.pure.ts","lineNumber":2315,"sourceCode":"     * @param image source for image\r\n     * @param options An object that sets options for the image's extraction.\r\n     * @returns ImageBitmap\r\n     */\r\n    public override async createImageBitmap(image: ImageBitmapSource, options?: ImageBitmapOptions): Promise<ImageBitmap> {\r\n        // Back-compat: Because of the previous Blob hack, this could be an array of BlobParts.\r\n        if (Array.isArray(image)) {\r\n            const arr = <Array<ArrayBuffer>>image;\r\n            if (arr.length) {\r\n                return this._engine.createImageBitmap(arr[0]);\r\n            }\r\n        }\r\n\r\n        if (image instanceof Blob) {\r\n            const data = await image.arrayBuffer();\r\n            return this._engine.createImageBitmap(data);\r\n        }\r\n\r\n        throw new Error(\"Unsupported data for createImageBitmap.\");\r\n    }\r\n\r\n    /**\r\n     * Resize an image and returns the image data as an uint8array\r\n     * @param image image to resize\r\n     * @param bufferWidth destination buffer width\r\n     * @param bufferHeight destination buffer height\r\n     * @returns an uint8array containing RGBA values of bufferWidth * bufferHeight size\r\n     */\r\n    public override resizeImageBitmap(image: ImageBitmap, bufferWidth: number, bufferHeight: number): Uint8Array {\r\n        return this._engine.resizeImageBitmap(image, bufferWidth, bufferHeight);\r\n    }\r\n\r\n    /** @internal */\r\n    public override _createHardwareTexture(): IHardwareTextureWrapper {\r\n        return new NativeHardwareTexture(this._createTexture() as NativeTexture, this._engine);\r\n    }\r\n\r","sourceCodeStart":2297,"sourceCodeEnd":2333,"githubUrl":"https://github.com/BabylonJS/Babylon.js/blob/0592b347b8a4ee0236089ea86a749cacfdb266d8/packages/dev/core/src/Engines/thinNativeEngine.pure.ts#L2297-L2333","documentation":"ThinNativeEngine's createImageBitmap implementation supports Image-like objects and Blob inputs only; anything else (string URLs, HTMLImageElement substitutes, typed arrays) falls through to this throw because the native engine has no generic decoder here.","triggerScenarios":"Calling engine.createImageBitmap(data) where data is neither an ImageBitmap-compatible source handled above the check nor a Blob — e.g. a string URL, an ArrayBuffer, or a Uint8Array.","commonSituations":"Code ported from WebGL Babylon.js that passed image URLs or raw byte arrays to createImageBitmap and now runs on Babylon Native.","solutions":["Convert the input to a Blob first (e.g. new Blob([uint8array], { type: \"image/png\" })).","For a URL, fetch it into a Blob before calling createImageBitmap.","Decode the image manually and use createTexture/raw texture APIs with the pixel data instead."],"exampleFix":"// before\nconst bmp = await engine.createImageBitmap(\"file:///tex.png\");\n\n// after\nconst resp = await fetch(\"file:///tex.png\");\nconst bmp = await engine.createImageBitmap(await resp.blob());","handlingStrategy":"type-guard","validationCode":"if (!(image instanceof Blob)) {\n  throw new TypeError(\"Native createImageBitmap accepts Blob inputs; convert first.\");\n}","typeGuard":"const isImageBitmapInput = (v: unknown): v is Blob => typeof Blob !== \"undefined\" && v instanceof Blob;","tryCatchPattern":"try {\n  return await engine.createImageBitmap(input);\n} catch (e) {\n  if (e.message.includes(\"Unsupported data for createImageBitmap\")) {\n    const blob = input instanceof Blob ? input : new Blob([await toArrayBuffer(input)], { type: \"image/png\" });\n    return await engine.createImageBitmap(blob);\n  } else throw e;\n}","preventionTips":["Always hand createImageBitmap a Blob on the native path.","Convert URLs via fetch().then(r => r.blob()) before decoding.","Centralize image decoding in one helper that branches between web and native engines."],"tags":["native","image-decoding","invalid-argument"],"backgroundTag":"unsupported-image-data","analyzedSha":"0592b347b8a4ee0236089ea86a749cacfdb266d8","analyzedAt":"2026-08-30T15:11:20.442Z","schemaVersion":2},"datasetVersion":"2026-08-30T18:17:15.746Z"}