From a62de758dc6c222941dd20404d86b898fde2478a Mon Sep 17 00:00:00 2001 From: Sean Lilley Date: Wed, 15 Sep 2021 11:57:28 -0400 Subject: [PATCH 1/2] Fix unhandled error when obj or mtl is missing --- lib/readLines.js | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/lib/readLines.js b/lib/readLines.js index 0977b1c..106e9be 100644 --- a/lib/readLines.js +++ b/lib/readLines.js @@ -2,6 +2,7 @@ const fsExtra = require("fs-extra"); const Promise = require("bluebird"); const readline = require("readline"); +const events = require("events"); module.exports = readLines; @@ -15,23 +16,25 @@ module.exports = readLines; * @private */ function readLines(path, callback) { - return new Promise(function (resolve, reject) { - const stream = fsExtra.createReadStream(path); - stream.on("error", reject); - stream.on("end", resolve); + const stream = fsExtra.createReadStream(path); + return events.once(stream, "open").then(function () { + return new Promise(function (resolve, reject) { + stream.on("error", reject); + stream.on("end", resolve); - const lineReader = readline.createInterface({ - input: stream, + const lineReader = readline.createInterface({ + input: stream, + }); + + const callbackWrapper = function (line) { + try { + callback(line); + } catch (error) { + reject(error); + } + }; + + lineReader.on("line", callbackWrapper); }); - - const callbackWrapper = function (line) { - try { - callback(line); - } catch (error) { - reject(error); - } - }; - - lineReader.on("line", callbackWrapper); }); } From ab060bb185b051eab75a49fe0911b0b912473f36 Mon Sep 17 00:00:00 2001 From: Sean Lilley Date: Wed, 15 Sep 2021 12:06:52 -0400 Subject: [PATCH 2/2] Update CHANGES.md --- CHANGES.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 9688e18..f8f149d 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,5 +1,9 @@ # Change Log +### 3.1.3 - 2021-09-15 + +- Fixed bug where missing .mtl files were no longer being handled gracefully in Node 16. [#268](https://github.com/CesiumGS/obj2gltf/pull/268) + ### 3.1.2 - 2021-08-02 - Removed `minFilter` and `magFilter` from generated samplers so that runtime engines can use their preferred texture filtering. [#240](https://github.com/CesiumGS/obj2gltf/pull/240)