{"record":{"id":"c4006b5e3cd09523","repo":"BabylonJS/Babylon.js","slug":"unsupported-buffer-type","errorCode":null,"errorMessage":"Unsupported buffer type","messagePattern":"Unsupported buffer type","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/dev/core/src/Engines/thinNativeEngine.pure.ts","lineNumber":2085,"sourceCode":"\r\n                        texture.onLoadedObservable.notifyObservers(texture);\r\n                        texture.onLoadedObservable.clear();\r\n                    },\r\n                    () => {\r\n                        throw new Error(\"Could not load a native texture.\");\r\n                    }\r\n                );\r\n            };\r\n\r\n            if (fromData && buffer) {\r\n                if (buffer instanceof ArrayBuffer) {\r\n                    onload(new Uint8Array(buffer));\r\n                } else if (ArrayBuffer.isView(buffer)) {\r\n                    onload(buffer);\r\n                } else if (typeof buffer === \"string\") {\r\n                    onload(new Uint8Array(DecodeBase64UrlToBinary(buffer)));\r\n                } else {\r\n                    throw new Error(\"Unsupported buffer type\");\r\n                }\r\n            } else {\r\n                if (isBase64) {\r\n                    onload(new Uint8Array(DecodeBase64UrlToBinary(url)));\r\n                } else {\r\n                    this._loadFile(\r\n                        url,\r\n                        (data) => onload(new Uint8Array(data as ArrayBuffer)),\r\n                        undefined,\r\n                        undefined,\r\n                        true,\r\n                        (request?: IWebRequest, exception?: any) => {\r\n                            onInternalError(\"Unable to load \" + (request ? request.responseURL : url, exception));\r\n                        }\r\n                    );\r\n                }\r\n            }\r\n        }\r","sourceCodeStart":2067,"sourceCodeEnd":2103,"githubUrl":"https://github.com/BabylonJS/Babylon.js/blob/0592b347b8a4ee0236089ea86a749cacfdb266d8/packages/dev/core/src/Engines/thinNativeEngine.pure.ts#L2067-L2103","documentation":"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'.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Convert the value to a typed array first: new Uint8Array(await blob.arrayBuffer()).","If it is a string, ensure it is a base64 or data: URL string, not an http URL.","If it is raw pixel data, wrap it: onload(new Uint8Array(rawBytes)) equivalent before calling createTexture."],"exampleFix":"// before\nengine.createTexture(\"\", false, false, scene, 3, ok, err, blob, null, -1, \"\", \"\", null, true);\n\n// after\nconst bytes = new Uint8Array(await blob.arrayBuffer());\nengine.createTexture(\"\", false, false, scene, 3, ok, err, bytes, null, -1, \"\", \"\", null, true);","handlingStrategy":"type-guard","validationCode":"if (!(buffer instanceof ArrayBuffer) && !ArrayBuffer.isView(buffer) && !(typeof buffer === \"string\" && (buffer.startsWith(\"data:\") || /^[A-Za-z0-9+/=]+$/.test(buffer)))) {\n  throw new TypeError(\"createTexture buffer must be ArrayBuffer, typed array, or base64 string\");\n}","typeGuard":"const isNativeTextureBuffer = (b: unknown): b is ArrayBuffer | ArrayBufferView | string =>\n  b instanceof ArrayBuffer || ArrayBuffer.isView(b as object) || typeof b === \"string\";","tryCatchPattern":"try {\n  engine.createTexture(\"\", false, false, scene, 3, onLoad, onError, buffer, null, -1, \"\", \"\", null, true);\n} catch (e) {\n  if (e.message === \"Unsupported buffer type\") {\n    const bytes = new Uint8Array(await toArrayBuffer(buffer));\n    engine.createTexture(\"\", false, false, scene, 3, onLoad, onError, bytes, null, -1, \"\", \"\", null, true);\n  } else throw e;\n}","preventionTips":["Always convert Blob/File/Image inputs to Uint8Array before passing as buffer.","Never pass http(s) URL strings as buffer with fromData=true.","Type buffer parameters as ArrayBuffer | ArrayBufferView | string in your wrappers."],"tags":["native","texture-loading","invalid-argument"],"backgroundTag":"unsupported-buffer-type","analyzedSha":"0592b347b8a4ee0236089ea86a749cacfdb266d8","analyzedAt":"2026-08-30T15:11:20.442Z","schemaVersion":2},"datasetVersion":"2026-08-30T18:17:15.746Z"}