Browse Source

GLTFLoader: Make error when loading textures with no data clear

If GLTFLoader is used to load a texture with no uri or bufferView, it
uses an empty uri which results in FileLoader loading the HTML document
from which the call originates. The resulting document is then fed into
an actual image loader such as KTX2Loader or BitmapLoader, which tends
to generate hard to understand errors.

This change detects the error early and throws a special message to make
debugging easier.
Arseny Kapoulkine 4 years ago
parent
commit
5d6ad11735
2 changed files with 9 additions and 1 deletions
  1. 5 1
      examples/js/loaders/GLTFLoader.js
  2. 4 0
      examples/jsm/loaders/GLTFLoader.js

+ 5 - 1
examples/js/loaders/GLTFLoader.js

@@ -2443,6 +2443,10 @@ THREE.GLTFLoader = ( function () {
 
 
 			} );
 			} );
 
 
+		} else if ( source.uri === undefined ) {
+
+			throw new Error( 'THREE.GLTFLoader: Image ' + textureIndex + ' is missing URI and bufferView' );
+
 		}
 		}
 
 
 		return Promise.resolve( sourceURI ).then( function ( sourceURI ) {
 		return Promise.resolve( sourceURI ).then( function ( sourceURI ) {
@@ -2626,7 +2630,7 @@ THREE.GLTFLoader = ( function () {
 				if ( useFlatShading ) cachedMaterial.flatShading = true;
 				if ( useFlatShading ) cachedMaterial.flatShading = true;
 				if ( useMorphTargets ) cachedMaterial.morphTargets = true;
 				if ( useMorphTargets ) cachedMaterial.morphTargets = true;
 				if ( useMorphNormals ) cachedMaterial.morphNormals = true;
 				if ( useMorphNormals ) cachedMaterial.morphNormals = true;
-				
+
 				if ( useVertexTangents ) {
 				if ( useVertexTangents ) {
 
 
 					cachedMaterial.vertexTangents = true;
 					cachedMaterial.vertexTangents = true;

+ 4 - 0
examples/jsm/loaders/GLTFLoader.js

@@ -2508,6 +2508,10 @@ var GLTFLoader = ( function () {
 
 
 			} );
 			} );
 
 
+		} else if ( source.uri === undefined ) {
+
+			throw new Error( 'THREE.GLTFLoader: Image ' + textureIndex + ' is missing URI and bufferView' );
+
 		}
 		}
 
 
 		return Promise.resolve( sourceURI ).then( function ( sourceURI ) {
 		return Promise.resolve( sourceURI ).then( function ( sourceURI ) {