FileLoader cannot handle request.abort()

The change, that let’s FileLoader cache duplicate requests by default, introduced a problem, when aborting a request before it’s loaded.

XMLHttpRequest.abort() does not tirgger ‘load’ or ‘error’ events but instead an ‘abort’ event.

Because that event is not handled, the request will be stuck in the FileLoaders ‘loading’ object, that is used to determine, if a file is already loading.

Demo jsfiddle

By adding a listener for ‘abort’ this could be prevented:

request.addEventListener( 'abort', function ( event ) {
    ... handle the same way an error would be handled
}, false );

I’m not sure, if handling it as an error is the way to go, because aborting has to be called on purpose, but this is how i do it for now.

Three.js version
  • r88+
Browser
  • All of them
OS
  • All of them

Author: Fantashit

1 thought on “FileLoader cannot handle request.abort()

  1. I’m not sure, if handling it as an error is the way to go, because aborting has to be called on purpose, but this is how i do it for now.

    I think it’s okay if the engine internally handles this case as an error (in the sense of the request was not completed as expected). The code of the new event handler could be equal to the current one for the error event:

    request.addEventListener( ‘error’, function ( event ) {
    var callbacks = loading[ url ];
    delete loading[ url ];
    for ( var i = 0, il = callbacks.length; i < il; i ++ ) {
    var callback = callbacks[ i ];
    if ( callback.onError ) callback.onError( event );
    }
    scope.manager.itemEnd( url );
    scope.manager.itemError( url );
    }, false );

Comments are closed.