Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 21 additions & 5 deletions src/loaders/ImageBitmapLoader.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { Cache } from './Cache.js';
import { Loader } from './Loader.js';

const _errorMap = new WeakMap();

/**
* A loader for loading images as an [ImageBitmap]{@link https://developer.mozilla.org/en-US/docs/Web/API/ImageBitmap}.
* An `ImageBitmap` provides an asynchronous and resource efficient pathway to prepare
Expand All @@ -11,7 +13,7 @@ import { Loader } from './Loader.js';
*
* You need to set the equivalent options via {@link ImageBitmapLoader#setOptions} instead.
*
* Also note that unlike {@link FileLoader}, this loader does not avoid multiple concurrent requests to the same URL.
* Also note that unlike {@link FileLoader}, this loader avoids multiple concurrent requests to the same URL only if `Cache` is enabled.
*
* ```js
* const loader = new THREE.ImageBitmapLoader();
Expand Down Expand Up @@ -111,15 +113,27 @@ class ImageBitmapLoader extends Loader {

cached.then( imageBitmap => {

if ( onLoad ) onLoad( imageBitmap );
// check if there is an error for the cached promise

if ( _errorMap.has( cached ) === true ) {

if ( onError ) onError( _errorMap.get( cached ) );

scope.manager.itemError( url );
scope.manager.itemEnd( url );

scope.manager.itemEnd( url );
} else {

} ).catch( e => {
if ( onLoad ) onLoad( imageBitmap );

if ( onError ) onError( e );
scope.manager.itemEnd( url );

return imageBitmap;

}

} );

return;

}
Expand Down Expand Up @@ -163,6 +177,8 @@ class ImageBitmapLoader extends Loader {

if ( onError ) onError( e );

_errorMap.set( promise, e );

Cache.remove( url );

scope.manager.itemError( url );
Expand Down