Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix unhandled error when mtl is missing #268

Merged
merged 2 commits into from Sep 15, 2021
Merged

Fix unhandled error when mtl is missing #268

merged 2 commits into from Sep 15, 2021

Conversation

lilleyse
Copy link
Contributor

While testing out Node 16.9.0 for #266 I noticed that missing mtl files were not being handled gracefully anymore. Both unit tests and command line conversions were failing.

slilley@Lithium:~/Code/obj2gltf$ node bin/obj2gltf.js -i ./specs/data/box-missing-mtllib/box-missing-mtllib.obj -o ~/Desktop/test.gltf
node:events:371
      throw er; // Unhandled 'error' event
      ^

Error: ENOENT: no such file or directory, open '/box.mtl'
Emitted 'error' event on Interface instance at:
    at ReadStream.onerror (node:readline:265:10)
    at ReadStream.emit (node:events:406:35)
    at emitErrorNT (node:internal/streams/destroy:157:8)
    at emitErrorCloseNT (node:internal/streams/destroy:122:3)
    at processTicksAndRejections (node:internal/process/task_queues:83:21) {
  errno: -2,
  code: 'ENOENT',
  syscall: 'open',
  path: '/box.mtl'
}

Previously in Node 14.17.1 I would see

slilley@Lithium:~/Code/obj2gltf$ node bin/obj2gltf.js -i ./specs/data/box-missing-mtllib/box-missing-mtllib.obj -o ~/Desktop/test.gltf
ENOENT: no such file or directory, open '/box.mtl'
Could not read material file at /box.mtl. Attempting to read the material file from within the obj directory instead.
ENOENT: no such file or directory, open '/home/slilley/Code/obj2gltf/specs/data/box-missing-mtllib/box.mtl'
Could not read material file at /home/slilley/Code/obj2gltf/specs/data/box-missing-mtllib/box.mtl. Using default material instead.
Total: 12.839ms

Which would produce a glTF file with a default material.

The bug ended up being similar to the one here: https://stackoverflow.com/questions/62885667/why-does-this-readline-async-iterator-not-work-properly/62887022#62887022. The suggested fix was to wait for the stream to open before initializing readline. This seemed to do the trick.

@IanLilleyT IanLilleyT merged commit 049f7af into main Sep 15, 2021
@IanLilleyT IanLilleyT deleted the fix-missing-mtl branch September 15, 2021 16:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants