From 75c8dc6163a8bcccd9fdf9eb86082f1cc8a21468 Mon Sep 17 00:00:00 2001 From: Sean Lilley Date: Tue, 5 Feb 2019 18:41:32 -0500 Subject: [PATCH] Remove string size limitation --- CHANGES.md | 1 + lib/writeGltf.js | 8 ++++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 6fbeae8..193a346 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -5,6 +5,7 @@ Change Log * Breaking changes * The `--materialsCommon` flag has been removed. Use `--unlit` instead which uses the `KHR_materials_unlit` extension. [#152](https://github.com/AnalyticalGraphicsInc/obj2gltf/pull/152) +* No longer throws an error always if the glTF buffer is greater than 192 MB. The string node size limitation increased in Node 9.0.0. See https://bugs.chromium.org/p/v8/issues/detail?id=6148#c10. ### 2.3.2 2018-11-02 diff --git a/lib/writeGltf.js b/lib/writeGltf.js index 3fadaa6..d835a51 100644 --- a/lib/writeGltf.js +++ b/lib/writeGltf.js @@ -145,12 +145,12 @@ function writeEmbeddedBuffer(gltf) { var buffer = gltf.buffers[0]; var source = buffer.extras._obj2gltf.source; - // Buffers larger than ~192MB cannot be base64 encoded due to a NodeJS limitation. Source: https://github.com/nodejs/node/issues/4266 - if (source.length > 201326580) { + try { + buffer.uri = 'data:application/octet-stream;base64,' + source.toString('base64'); + } catch(error) { + // In some versions of Node a buffer larger than ~192MB cannot be base64 encoded due to string size limitations. Source: https://stackoverflow.com/posts/47781288/revisions throw new RuntimeError('Buffer is too large to embed in the glTF. Use the --separate flag instead.'); } - - buffer.uri = 'data:application/octet-stream;base64,' + source.toString('base64'); } function writeEmbeddedTextures(gltf) {