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

TGALoader: Bubble parsing errors. #26497

Merged
merged 2 commits into from
Jul 26, 2023
Merged
Show file tree
Hide file tree
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
20 changes: 10 additions & 10 deletions examples/jsm/loaders/TGALoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class TGALoader extends DataTextureLoader {
case TGA_TYPE_RLE_INDEXED:
if ( header.colormap_length > 256 || header.colormap_size !== 24 || header.colormap_type !== 1 ) {

console.error( 'THREE.TGALoader: Invalid type colormap data for indexed type.' );
throw new Error( 'THREE.TGALoader: Invalid type colormap data for indexed type.' );

}

Expand All @@ -39,7 +39,7 @@ class TGALoader extends DataTextureLoader {
case TGA_TYPE_RLE_GREY:
if ( header.colormap_type ) {

console.error( 'THREE.TGALoader: Invalid type colormap data for colormap type.' );
throw new Error( 'THREE.TGALoader: Invalid type colormap data for colormap type.' );

}

Expand All @@ -48,20 +48,20 @@ class TGALoader extends DataTextureLoader {
// What the need of a file without data ?

case TGA_TYPE_NO_DATA:
console.error( 'THREE.TGALoader: No data.' );
throw new Error( 'THREE.TGALoader: No data.' );

// Invalid type ?

default:
console.error( 'THREE.TGALoader: Invalid type "%s".', header.image_type );
throw new Error( 'THREE.TGALoader: Invalid type ' + header.image_type );

}

// check image width and height

if ( header.width <= 0 || header.height <= 0 ) {

console.error( 'THREE.TGALoader: Invalid image size.' );
throw new Error( 'THREE.TGALoader: Invalid image size.' );

}

Expand All @@ -70,7 +70,7 @@ class TGALoader extends DataTextureLoader {
if ( header.pixel_size !== 8 && header.pixel_size !== 16 &&
header.pixel_size !== 24 && header.pixel_size !== 32 ) {

console.error( 'THREE.TGALoader: Invalid pixel size "%s".', header.pixel_size );
throw new Error( 'THREE.TGALoader: Invalid pixel size ' + header.pixel_size );

}

Expand Down Expand Up @@ -365,7 +365,7 @@ class TGALoader extends DataTextureLoader {
break;

default:
console.error( 'THREE.TGALoader: Format not supported.' );
throw new Error( 'THREE.TGALoader: Format not supported.' );
break;

}
Expand All @@ -391,7 +391,7 @@ class TGALoader extends DataTextureLoader {
break;

default:
console.error( 'THREE.TGALoader: Format not supported.' );
throw new Error( 'THREE.TGALoader: Format not supported.' );
break;

}
Expand Down Expand Up @@ -422,7 +422,7 @@ class TGALoader extends DataTextureLoader {
TGA_ORIGIN_UL = 0x02,
TGA_ORIGIN_UR = 0x03;

if ( buffer.length < 19 ) console.error( 'THREE.TGALoader: Not enough data to contain header.' );
if ( buffer.length < 19 ) throw new Error( 'THREE.TGALoader: Not enough data to contain header.' );

let offset = 0;

Expand Down Expand Up @@ -450,7 +450,7 @@ class TGALoader extends DataTextureLoader {

if ( header.id_length + offset > buffer.length ) {

console.error( 'THREE.TGALoader: No data.' );
throw new Error( 'THREE.TGALoader: No data.' );

}

Expand Down
23 changes: 21 additions & 2 deletions src/loaders/DataTextureLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,28 @@ class DataTextureLoader extends Loader {
loader.setWithCredentials( scope.withCredentials );
loader.load( url, function ( buffer ) {

const texData = scope.parse( buffer ); // TODO: Use try/catch here and throw errors in derived loaders, see #26412
let texData;

if ( ! texData ) return onError();
try {

texData = scope.parse( buffer );

} catch ( error ) {

if ( onError !== undefined ) {

onError( error );

} else {

console.error( error );
return;

}

}

if ( ! texData ) return onError(); // TODO: Remove this when all loaders properly throw errors

if ( texData.image !== undefined ) {

Expand Down