浏览代码

Catch parser exceptions in MMDLoader (#25966)

David Wu 2 年之前
父节点
当前提交
c25f9a5339
共有 1 个文件被更改,包括 37 次插入5 次删除
  1. 37 5
      examples/jsm/loaders/MMDLoader.js

+ 37 - 5
examples/jsm/loaders/MMDLoader.js

@@ -226,7 +226,15 @@ class MMDLoader extends Loader {
 			.setWithCredentials( this.withCredentials )
 			.setWithCredentials( this.withCredentials )
 			.load( url, function ( buffer ) {
 			.load( url, function ( buffer ) {
 
 
-				onLoad( parser.parsePmd( buffer, true ) );
+				try {
+
+					onLoad( parser.parsePmd( buffer, true ) );
+
+				} catch ( e ) {
+
+					if ( onError ) onError( e );
+
+				}
 
 
 			}, onProgress, onError );
 			}, onProgress, onError );
 
 
@@ -252,7 +260,15 @@ class MMDLoader extends Loader {
 			.setWithCredentials( this.withCredentials )
 			.setWithCredentials( this.withCredentials )
 			.load( url, function ( buffer ) {
 			.load( url, function ( buffer ) {
 
 
-				onLoad( parser.parsePmx( buffer, true ) );
+				try {
+
+					onLoad( parser.parsePmx( buffer, true ) );
+
+				} catch ( e ) {
+
+					if ( onError ) onError( e );
+
+				}
 
 
 			}, onProgress, onError );
 			}, onProgress, onError );
 
 
@@ -287,9 +303,17 @@ class MMDLoader extends Loader {
 
 
 			this.loader.load( urls[ i ], function ( buffer ) {
 			this.loader.load( urls[ i ], function ( buffer ) {
 
 
-				vmds.push( parser.parseVmd( buffer, true ) );
+				try {
 
 
-				if ( vmds.length === vmdNum ) onLoad( parser.mergeVmds( vmds ) );
+					vmds.push( parser.parseVmd( buffer, true ) );
+
+					if ( vmds.length === vmdNum ) onLoad( parser.mergeVmds( vmds ) );
+
+				} catch ( e ) {
+
+					if ( onError ) onError( e );
+
+				}
 
 
 			}, onProgress, onError );
 			}, onProgress, onError );
 
 
@@ -318,7 +342,15 @@ class MMDLoader extends Loader {
 			.setWithCredentials( this.withCredentials )
 			.setWithCredentials( this.withCredentials )
 			.load( url, function ( text ) {
 			.load( url, function ( text ) {
 
 
-				onLoad( parser.parseVpd( text, true ) );
+				try {
+
+					onLoad( parser.parseVpd( text, true ) );
+
+				} catch ( e ) {
+
+					if ( onError ) onError( e );
+
+				}
 
 
 			}, onProgress, onError );
 			}, onProgress, onError );