Three.js: PCDLoader does not handle errors correctly

Created on 24 Aug 2018  路  8Comments  路  Source: mrdoob/three.js

Description of the problem

The PCDLoader doesn't handle errors well. If there's an error when parsing, the error handler passed in is not called and the resulting exception is only caught by a global process handler. This may apply to all loaders as if there's an error in the setTimeout method used for loading there's no way to catch that exception.

        var url = 'https://threejs.org/examples/textures/sprites/disc.png';
        var loader = new THREE.PCDLoader().load(
          url, 
          () => alert('something loaded'),
          () => {},
          () => alert('error handler - never gets called')
        );
Three.js version
  • r91
Browser
  • [x] All of them
  • [x] Chrome
  • [ ] Firefox
  • [ ] Internet Explorer
OS
  • [x] All of them
  • [ ] Windows
  • [x] macOS
  • [x] Linux
  • [ ] Android
  • [ ] iOS
Hardware Requirements (graphics card, VR Device, ...)

any

Loaders

Most helpful comment

Sure. Why not? I'll get something up later today

All 8 comments

Could you attach files here that the loader has trouble parsing?

Sure. Here's an image file:

disc

Maybe something like this would help to improve error handling:

try {

    onLoad( scope.parse( data, url ) );

} catch ( e ) {

    if ( onError ) onError( e );

}

The onError() callback of PCDLoader.load() would now be able to handle exceptions caused by an invalid format.

Don鈥檛 think that will work. The onLoad method calls setTimeout internally. I would think you鈥檇 need to put the try catch there

I was able to catch the error with this code when trying to load the following URL with PCDLoader:

https://threejs.org/examples/textures/sprites/disc.png

Can you also give it a try?

You're right. That worked. I'm surprised given that it does seem to be calling onLoad in a setTimeout, but perhaps because the timeout is 0?

It would be good to add a re-throw if no onError method is specified, but otherwise that seems to solve the issue.

Would you like to do a PR and add the code snippet to PCDLoader:innocent:?

Sure. Why not? I'll get something up later today

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jack-jun picture jack-jun  路  3Comments

akshaysrin picture akshaysrin  路  3Comments

makc picture makc  路  3Comments

ghost picture ghost  路  3Comments

fuzihaofzh picture fuzihaofzh  路  3Comments