Three.js: FileLoader cannot handle request.abort()

Created on 6 Aug 2018  路  3Comments  路  Source: mrdoob/three.js

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
  • [x] r88+
Browser
  • [x] All of them
OS
  • [x] All of them
Suggestion

Most helpful comment

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:

https://github.com/mrdoob/three.js/blob/6201c9ac8c8a384ebc475e5bdb7c6ee0d75885f7/src/loaders/FileLoader.js#L224-L240

All 3 comments

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:

https://github.com/mrdoob/three.js/blob/6201c9ac8c8a384ebc475e5bdb7c6ee0d75885f7/src/loaders/FileLoader.js#L224-L240

@okitu Would you like to do a PR with the change?

@Mugen87 Most certainly sir.

14674

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ghost picture ghost  路  3Comments

boyravikumar picture boyravikumar  路  3Comments

makc picture makc  路  3Comments

yqrashawn picture yqrashawn  路  3Comments

donmccurdy picture donmccurdy  路  3Comments