From fb8a58a1365fb8ef62a4c6ec16facea13cceb0c8 Mon Sep 17 00:00:00 2001 From: Christopher Pruijsen Date: Sun, 13 Sep 2026 09:32:51 +0000 Subject: [PATCH] fix(GLTFExporter): encode data URIs in chunks to avoid stack overflow readAsDataURL spread the whole binary buffer into String.fromCharCode, which throws RangeError: Maximum call stack size exceeded for large exports. Encode the bytes in 32KB chunks instead. --- src/exporters/GLTFExporter.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/exporters/GLTFExporter.js b/src/exporters/GLTFExporter.js index d50ed0b5..fe9dc571 100644 --- a/src/exporters/GLTFExporter.js +++ b/src/exporters/GLTFExporter.js @@ -33,8 +33,15 @@ import { version } from '../_polyfill/constants' async function readAsDataURL(blob) { const buffer = await blob.arrayBuffer() - const data = btoa(String.fromCharCode(...new Uint8Array(buffer))) - return `data:${blob.type || ''};base64,${data}` + const bytes = new Uint8Array(buffer) + + // Spread of a large byte array into fromCharCode overflows the call stack, so encode in chunks + let data = '' + for (let i = 0; i < bytes.length; i += 0x8000) { + data += String.fromCharCode(...bytes.subarray(i, i + 0x8000)) + } + + return `data:${blob.type || ''};base64,${btoa(data)}` } let _renderer