Browse Source

Handling exception on load errors

Added exception to the load and import functions of the plugin.
Nof if the onError function is set, no exception will be actively
thrown, but the onError will be triggered.
Raanan Weber 8 years ago
parent
commit
59babcb49b

+ 53 - 45
src/Loading/Plugins/babylon.babylonFileLoader.ts

@@ -38,7 +38,7 @@
 
 
             return false;
             return false;
         },
         },
-        importMesh: (meshesNames: any, scene: Scene, data: any, rootUrl: string, meshes: AbstractMesh[], particleSystems: ParticleSystem[], skeletons: Skeleton[]): boolean => {
+        importMesh: (meshesNames: any, scene: Scene, data: any, rootUrl: string, meshes: AbstractMesh[], particleSystems: ParticleSystem[], skeletons: Skeleton[], onError?: (message: string, exception?: any) => void): boolean => {
             // Entire method running in try block, so ALWAYS logs as far as it got, only actually writes details
             // Entire method running in try block, so ALWAYS logs as far as it got, only actually writes details
             // when SceneLoader.debugLogging = true (default), or exception encountered.
             // when SceneLoader.debugLogging = true (default), or exception encountered.
             // Everything stored in var log instead of writing separate lines to support only writing in exception,
             // Everything stored in var log instead of writing separate lines to support only writing in exception,
@@ -53,7 +53,7 @@
                 } else if (!Array.isArray(meshesNames)) {
                 } else if (!Array.isArray(meshesNames)) {
                     meshesNames = [meshesNames];
                     meshesNames = [meshesNames];
                 }
                 }
-                
+
                 if (parsedData.meshes !== undefined && parsedData.meshes !== null) {
                 if (parsedData.meshes !== undefined && parsedData.meshes !== null) {
                     var loadedSkeletonsIds = [];
                     var loadedSkeletonsIds = [];
                     var loadedMaterialsIds = [];
                     var loadedMaterialsIds = [];
@@ -68,7 +68,7 @@
                                 // Remove found mesh name from list.
                                 // Remove found mesh name from list.
                                 delete meshesNames[meshesNames.indexOf(parsedMesh.name)];
                                 delete meshesNames[meshesNames.indexOf(parsedMesh.name)];
                             }
                             }
-        
+
                             //Geometry?
                             //Geometry?
                             if (parsedMesh.geometryId !== undefined && parsedMesh.geometryId !== null) {
                             if (parsedMesh.geometryId !== undefined && parsedMesh.geometryId !== null) {
                                 //does the file contain geometries?
                                 //does the file contain geometries?
@@ -118,7 +118,7 @@
                                     }
                                     }
                                 }
                                 }
                             }
                             }
-        
+
                             // Material ?
                             // Material ?
                             if (parsedMesh.materialId) {
                             if (parsedMesh.materialId) {
                                 var materialFound = (loadedMaterialsIds.indexOf(parsedMesh.materialId) !== -1);
                                 var materialFound = (loadedMaterialsIds.indexOf(parsedMesh.materialId) !== -1);
@@ -151,7 +151,7 @@
                                     }
                                     }
                                 }
                                 }
                             }
                             }
-        
+
                             // Skeleton ?
                             // Skeleton ?
                             if (parsedMesh.skeletonId > -1 && parsedData.skeletons !== undefined && parsedData.skeletons !== null) {
                             if (parsedMesh.skeletonId > -1 && parsedData.skeletons !== undefined && parsedData.skeletons !== null) {
                                 var skeletonAlreadyLoaded = (loadedSkeletonsIds.indexOf(parsedMesh.skeletonId) > -1);
                                 var skeletonAlreadyLoaded = (loadedSkeletonsIds.indexOf(parsedMesh.skeletonId) > -1);
@@ -173,7 +173,7 @@
                             log += "\n\tMesh " + mesh.toString(fullDetails);
                             log += "\n\tMesh " + mesh.toString(fullDetails);
                         }
                         }
                     }
                     }
-        
+
                     // Connecting parents
                     // Connecting parents
                     var currentMesh: AbstractMesh;
                     var currentMesh: AbstractMesh;
                     for (index = 0, cache = scene.meshes.length; index < cache; index++) {
                     for (index = 0, cache = scene.meshes.length; index < cache; index++) {
@@ -183,7 +183,7 @@
                             currentMesh._waitingParentId = undefined;
                             currentMesh._waitingParentId = undefined;
                         }
                         }
                     }
                     }
-        
+
                     // freeze and compute world matrix application
                     // freeze and compute world matrix application
                     for (index = 0, cache = scene.meshes.length; index < cache; index++) {
                     for (index = 0, cache = scene.meshes.length; index < cache; index++) {
                         currentMesh = scene.meshes[index];
                         currentMesh = scene.meshes[index];
@@ -195,7 +195,7 @@
                         }
                         }
                     }
                     }
                 }
                 }
-    
+
                 // Particles
                 // Particles
                 if (parsedData.particleSystems !== undefined && parsedData.particleSystems !== null) {
                 if (parsedData.particleSystems !== undefined && parsedData.particleSystems !== null) {
                     for (index = 0, cache = parsedData.particleSystems.length; index < cache; index++) {
                     for (index = 0, cache = parsedData.particleSystems.length; index < cache; index++) {
@@ -209,17 +209,21 @@
                 return true;
                 return true;
 
 
             } catch (err) {
             } catch (err) {
-                Tools.Log(logOperation("importMesh", parsedData ? parsedData.producer : "Unknown") + log);
-                log = null;
-                throw err;
-
+                let msg = logOperation("importMesh", parsedData ? parsedData.producer : "Unknown") + log;
+                if (onError) {
+                    onError(msg, err);
+                } else {
+                    Tools.Log(msg);
+                    log = null;
+                    throw err;
+                }
             } finally {
             } finally {
                 if (log !== null && SceneLoader.loggingLevel !== SceneLoader.NO_LOGGING) {
                 if (log !== null && SceneLoader.loggingLevel !== SceneLoader.NO_LOGGING) {
                     Tools.Log(logOperation("importMesh", parsedData ? parsedData.producer : "Unknown") + (SceneLoader.loggingLevel !== SceneLoader.MINIMAL_LOGGING ? log : ""));
                     Tools.Log(logOperation("importMesh", parsedData ? parsedData.producer : "Unknown") + (SceneLoader.loggingLevel !== SceneLoader.MINIMAL_LOGGING ? log : ""));
                 }
                 }
             }
             }
         },
         },
-        load: (scene: Scene, data: string, rootUrl: string): boolean => {
+        load: (scene: Scene, data: string, rootUrl: string, onError?: (message: string, exception?: any) => void): boolean => {
             // Entire method running in try block, so ALWAYS logs as far as it got, only actually writes details
             // Entire method running in try block, so ALWAYS logs as far as it got, only actually writes details
             // when SceneLoader.debugLogging = true (default), or exception encountered.
             // when SceneLoader.debugLogging = true (default), or exception encountered.
             // Everything stored in var log instead of writing separate lines to support only writing in exception,
             // Everything stored in var log instead of writing separate lines to support only writing in exception,
@@ -229,7 +233,7 @@
                 var parsedData = JSON.parse(data);
                 var parsedData = JSON.parse(data);
                 log = "";
                 log = "";
                 var fullDetails = SceneLoader.loggingLevel === SceneLoader.DETAILED_LOGGING;
                 var fullDetails = SceneLoader.loggingLevel === SceneLoader.DETAILED_LOGGING;
-                
+
                 // Scene
                 // Scene
                 if (parsedData.useDelayedTextureLoading !== undefined && parsedData.useDelayedTextureLoading !== null) {
                 if (parsedData.useDelayedTextureLoading !== undefined && parsedData.useDelayedTextureLoading !== null) {
                     scene.useDelayedTextureLoading = parsedData.useDelayedTextureLoading && !BABYLON.SceneLoader.ForceFullSceneLoadingForIncremental;
                     scene.useDelayedTextureLoading = parsedData.useDelayedTextureLoading && !BABYLON.SceneLoader.ForceFullSceneLoadingForIncremental;
@@ -246,7 +250,7 @@
                 if (parsedData.gravity !== undefined && parsedData.gravity !== null) {
                 if (parsedData.gravity !== undefined && parsedData.gravity !== null) {
                     scene.gravity = BABYLON.Vector3.FromArray(parsedData.gravity);
                     scene.gravity = BABYLON.Vector3.FromArray(parsedData.gravity);
                 }
                 }
-                
+
                 // Fog
                 // Fog
                 if (parsedData.fogMode && parsedData.fogMode !== 0) {
                 if (parsedData.fogMode && parsedData.fogMode !== 0) {
                     scene.fogMode = parsedData.fogMode;
                     scene.fogMode = parsedData.fogMode;
@@ -262,7 +266,7 @@
                         case 3: log += "linear\n"; break;
                         case 3: log += "linear\n"; break;
                     }
                     }
                 }
                 }
-                
+
                 //Physics
                 //Physics
                 if (parsedData.physicsEnabled) {
                 if (parsedData.physicsEnabled) {
                     var physicsPlugin;
                     var physicsPlugin;
@@ -276,12 +280,12 @@
                     var physicsGravity = parsedData.physicsGravity ? BABYLON.Vector3.FromArray(parsedData.physicsGravity) : null;
                     var physicsGravity = parsedData.physicsGravity ? BABYLON.Vector3.FromArray(parsedData.physicsGravity) : null;
                     scene.enablePhysics(physicsGravity, physicsPlugin);
                     scene.enablePhysics(physicsGravity, physicsPlugin);
                 }
                 }
-                
+
                 // Metadata
                 // Metadata
                 if (parsedData.metadata !== undefined && parsedData.metadata !== null) {
                 if (parsedData.metadata !== undefined && parsedData.metadata !== null) {
                     scene.metadata = parsedData.metadata;
                     scene.metadata = parsedData.metadata;
                 }
                 }
-                
+
                 //collisions, if defined. otherwise, default is true
                 //collisions, if defined. otherwise, default is true
                 if (parsedData.collisionsEnabled !== undefined && parsedData.collisionsEnabled !== null) {
                 if (parsedData.collisionsEnabled !== undefined && parsedData.collisionsEnabled !== null) {
                     scene.collisionsEnabled = parsedData.collisionsEnabled;
                     scene.collisionsEnabled = parsedData.collisionsEnabled;
@@ -299,7 +303,7 @@
                         log += "\n\t\t" + light.toString(fullDetails);
                         log += "\n\t\t" + light.toString(fullDetails);
                     }
                     }
                 }
                 }
-    
+
                 // Animations
                 // Animations
                 if (parsedData.animations !== undefined && parsedData.animations !== null) {
                 if (parsedData.animations !== undefined && parsedData.animations !== null) {
                     for (index = 0, cache = parsedData.animations.length; index < cache; index++) {
                     for (index = 0, cache = parsedData.animations.length; index < cache; index++) {
@@ -314,7 +318,7 @@
                 if (parsedData.autoAnimate) {
                 if (parsedData.autoAnimate) {
                     scene.beginAnimation(scene, parsedData.autoAnimateFrom, parsedData.autoAnimateTo, parsedData.autoAnimateLoop, parsedData.autoAnimateSpeed || 1.0);
                     scene.beginAnimation(scene, parsedData.autoAnimateFrom, parsedData.autoAnimateTo, parsedData.autoAnimateLoop, parsedData.autoAnimateSpeed || 1.0);
                 }
                 }
-    
+
                 // Materials
                 // Materials
                 if (parsedData.materials !== undefined && parsedData.materials !== null) {
                 if (parsedData.materials !== undefined && parsedData.materials !== null) {
                     for (index = 0, cache = parsedData.materials.length; index < cache; index++) {
                     for (index = 0, cache = parsedData.materials.length; index < cache; index++) {
@@ -340,7 +344,7 @@
                         var parsedManager = MorphTargetManager.Parse(managerData, scene);
                         var parsedManager = MorphTargetManager.Parse(managerData, scene);
                     }
                     }
                 }
                 }
-    
+
                 // Skeletons
                 // Skeletons
                 if (parsedData.skeletons !== undefined && parsedData.skeletons !== null) {
                 if (parsedData.skeletons !== undefined && parsedData.skeletons !== null) {
                     for (index = 0, cache = parsedData.skeletons.length; index < cache; index++) {
                     for (index = 0, cache = parsedData.skeletons.length; index < cache; index++) {
@@ -350,7 +354,7 @@
                         log += "\n\t\t" + skeleton.toString(fullDetails);
                         log += "\n\t\t" + skeleton.toString(fullDetails);
                     }
                     }
                 }
                 }
-    
+
                 // Geometries
                 // Geometries
                 var geometries = parsedData.geometries;
                 var geometries = parsedData.geometries;
                 if (geometries !== undefined && geometries !== null) {
                 if (geometries !== undefined && geometries !== null) {
@@ -362,7 +366,7 @@
                             Geometry.Primitives.Box.Parse(parsedBox, scene);
                             Geometry.Primitives.Box.Parse(parsedBox, scene);
                         }
                         }
                     }
                     }
-    
+
                     // Spheres
                     // Spheres
                     var spheres = geometries.spheres;
                     var spheres = geometries.spheres;
                     if (spheres !== undefined && spheres !== null) {
                     if (spheres !== undefined && spheres !== null) {
@@ -371,7 +375,7 @@
                             Geometry.Primitives.Sphere.Parse(parsedSphere, scene);
                             Geometry.Primitives.Sphere.Parse(parsedSphere, scene);
                         }
                         }
                     }
                     }
-    
+
                     // Cylinders
                     // Cylinders
                     var cylinders = geometries.cylinders;
                     var cylinders = geometries.cylinders;
                     if (cylinders !== undefined && cylinders !== null) {
                     if (cylinders !== undefined && cylinders !== null) {
@@ -380,7 +384,7 @@
                             Geometry.Primitives.Cylinder.Parse(parsedCylinder, scene);
                             Geometry.Primitives.Cylinder.Parse(parsedCylinder, scene);
                         }
                         }
                     }
                     }
-    
+
                     // Toruses
                     // Toruses
                     var toruses = geometries.toruses;
                     var toruses = geometries.toruses;
                     if (toruses !== undefined && toruses !== null) {
                     if (toruses !== undefined && toruses !== null) {
@@ -389,7 +393,7 @@
                             Geometry.Primitives.Torus.Parse(parsedTorus, scene);
                             Geometry.Primitives.Torus.Parse(parsedTorus, scene);
                         }
                         }
                     }
                     }
-    
+
                     // Grounds
                     // Grounds
                     var grounds = geometries.grounds;
                     var grounds = geometries.grounds;
                     if (grounds !== undefined && grounds !== null) {
                     if (grounds !== undefined && grounds !== null) {
@@ -398,7 +402,7 @@
                             Geometry.Primitives.Ground.Parse(parsedGround, scene);
                             Geometry.Primitives.Ground.Parse(parsedGround, scene);
                         }
                         }
                     }
                     }
-    
+
                     // Planes
                     // Planes
                     var planes = geometries.planes;
                     var planes = geometries.planes;
                     if (planes !== undefined && planes !== null) {
                     if (planes !== undefined && planes !== null) {
@@ -407,7 +411,7 @@
                             Geometry.Primitives.Plane.Parse(parsedPlane, scene);
                             Geometry.Primitives.Plane.Parse(parsedPlane, scene);
                         }
                         }
                     }
                     }
-    
+
                     // TorusKnots
                     // TorusKnots
                     var torusKnots = geometries.torusKnots;
                     var torusKnots = geometries.torusKnots;
                     if (torusKnots !== undefined && torusKnots !== null) {
                     if (torusKnots !== undefined && torusKnots !== null) {
@@ -416,7 +420,7 @@
                             Geometry.Primitives.TorusKnot.Parse(parsedTorusKnot, scene);
                             Geometry.Primitives.TorusKnot.Parse(parsedTorusKnot, scene);
                         }
                         }
                     }
                     }
-    
+
                     // VertexData
                     // VertexData
                     var vertexData = geometries.vertexData;
                     var vertexData = geometries.vertexData;
                     if (vertexData !== undefined && vertexData !== null) {
                     if (vertexData !== undefined && vertexData !== null) {
@@ -426,7 +430,7 @@
                         }
                         }
                     }
                     }
                 }
                 }
-    
+
                 // Meshes
                 // Meshes
                 if (parsedData.meshes !== undefined && parsedData.meshes !== null) {
                 if (parsedData.meshes !== undefined && parsedData.meshes !== null) {
                     for (index = 0, cache = parsedData.meshes.length; index < cache; index++) {
                     for (index = 0, cache = parsedData.meshes.length; index < cache; index++) {
@@ -436,7 +440,7 @@
                         log += "\n\t\t" + mesh.toString(fullDetails);
                         log += "\n\t\t" + mesh.toString(fullDetails);
                     }
                     }
                 }
                 }
-    
+
                 // Cameras
                 // Cameras
                 if (parsedData.cameras !== undefined && parsedData.cameras !== null) {
                 if (parsedData.cameras !== undefined && parsedData.cameras !== null) {
                     for (index = 0, cache = parsedData.cameras.length; index < cache; index++) {
                     for (index = 0, cache = parsedData.cameras.length; index < cache; index++) {
@@ -449,7 +453,7 @@
                 if (parsedData.activeCameraID !== undefined && parsedData.activeCameraID !== null) {
                 if (parsedData.activeCameraID !== undefined && parsedData.activeCameraID !== null) {
                     scene.setActiveCameraByID(parsedData.activeCameraID);
                     scene.setActiveCameraByID(parsedData.activeCameraID);
                 }
                 }
-    
+
                 // Browsing all the graph to connect the dots
                 // Browsing all the graph to connect the dots
                 for (index = 0, cache = scene.cameras.length; index < cache; index++) {
                 for (index = 0, cache = scene.cameras.length; index < cache; index++) {
                     var camera = scene.cameras[index];
                     var camera = scene.cameras[index];
@@ -466,7 +470,7 @@
                         light._waitingParentId = undefined;
                         light._waitingParentId = undefined;
                     }
                     }
                 }
                 }
-    
+
                 // Sounds
                 // Sounds
                 var loadedSounds: Sound[] = [];
                 var loadedSounds: Sound[] = [];
                 var loadedSound: Sound;
                 var loadedSound: Sound;
@@ -489,7 +493,7 @@
                 }
                 }
 
 
                 loadedSounds = [];
                 loadedSounds = [];
-    
+
                 // Connect parents & children and parse actions
                 // Connect parents & children and parse actions
                 for (index = 0, cache = scene.meshes.length; index < cache; index++) {
                 for (index = 0, cache = scene.meshes.length; index < cache; index++) {
                     var mesh = scene.meshes[index];
                     var mesh = scene.meshes[index];
@@ -502,7 +506,7 @@
                         mesh._waitingActions = undefined;
                         mesh._waitingActions = undefined;
                     }
                     }
                 }
                 }
-    
+
                 // freeze world matrix application
                 // freeze world matrix application
                 for (index = 0, cache = scene.meshes.length; index < cache; index++) {
                 for (index = 0, cache = scene.meshes.length; index < cache; index++) {
                     var currentMesh = scene.meshes[index];
                     var currentMesh = scene.meshes[index];
@@ -513,7 +517,7 @@
                         currentMesh.computeWorldMatrix(true);
                         currentMesh.computeWorldMatrix(true);
                     }
                     }
                 }
                 }
-    
+
                 // Particles Systems
                 // Particles Systems
                 if (parsedData.particleSystems !== undefined && parsedData.particleSystems !== null) {
                 if (parsedData.particleSystems !== undefined && parsedData.particleSystems !== null) {
                     for (index = 0, cache = parsedData.particleSystems.length; index < cache; index++) {
                     for (index = 0, cache = parsedData.particleSystems.length; index < cache; index++) {
@@ -521,7 +525,7 @@
                         ParticleSystem.Parse(parsedParticleSystem, scene, rootUrl);
                         ParticleSystem.Parse(parsedParticleSystem, scene, rootUrl);
                     }
                     }
                 }
                 }
-    
+
                 // Lens flares
                 // Lens flares
                 if (parsedData.lensFlareSystems !== undefined && parsedData.lensFlareSystems !== null) {
                 if (parsedData.lensFlareSystems !== undefined && parsedData.lensFlareSystems !== null) {
                     for (index = 0, cache = parsedData.lensFlareSystems.length; index < cache; index++) {
                     for (index = 0, cache = parsedData.lensFlareSystems.length; index < cache; index++) {
@@ -529,7 +533,7 @@
                         LensFlareSystem.Parse(parsedLensFlareSystem, scene, rootUrl);
                         LensFlareSystem.Parse(parsedLensFlareSystem, scene, rootUrl);
                     }
                     }
                 }
                 }
-    
+
                 // Shadows
                 // Shadows
                 if (parsedData.shadowGenerators !== undefined && parsedData.shadowGenerators !== null) {
                 if (parsedData.shadowGenerators !== undefined && parsedData.shadowGenerators !== null) {
                     for (index = 0, cache = parsedData.shadowGenerators.length; index < cache; index++) {
                     for (index = 0, cache = parsedData.shadowGenerators.length; index < cache; index++) {
@@ -537,7 +541,7 @@
                         ShadowGenerator.Parse(parsedShadowGenerator, scene);
                         ShadowGenerator.Parse(parsedShadowGenerator, scene);
                     }
                     }
                 }
                 }
-                
+
                 // Lights exclusions / inclusions
                 // Lights exclusions / inclusions
                 for (index = 0, cache = scene.lights.length; index < cache; index++) {
                 for (index = 0, cache = scene.lights.length; index < cache; index++) {
                     var light = scene.lights[index];
                     var light = scene.lights[index];
@@ -567,20 +571,24 @@
                         light._includedOnlyMeshesIds = [];
                         light._includedOnlyMeshesIds = [];
                     }
                     }
                 }
                 }
-    
+
                 // Actions (scene)
                 // Actions (scene)
                 if (parsedData.actions !== undefined && parsedData.actions !== null) {
                 if (parsedData.actions !== undefined && parsedData.actions !== null) {
                     ActionManager.Parse(parsedData.actions, null, scene);
                     ActionManager.Parse(parsedData.actions, null, scene);
                 }
                 }
-    
+
                 // Finish
                 // Finish
                 return true;
                 return true;
 
 
             } catch (err) {
             } catch (err) {
-                Tools.Log(logOperation("importScene", parsedData ? parsedData.producer : "Unknown") + log);
-                log = null;
-                throw err;
-
+                let msg = logOperation("importScene", parsedData ? parsedData.producer : "Unknown") + log;
+                if (onError) {
+                    onError(msg, err);
+                } else {
+                    Tools.Log(msg);
+                    log = null;
+                    throw err;
+                }
             } finally {
             } finally {
                 if (log !== null && SceneLoader.loggingLevel !== SceneLoader.NO_LOGGING) {
                 if (log !== null && SceneLoader.loggingLevel !== SceneLoader.NO_LOGGING) {
                     Tools.Log(logOperation("importScene", parsedData ? parsedData.producer : "Unknown") + (SceneLoader.loggingLevel !== SceneLoader.MINIMAL_LOGGING ? log : ""));
                     Tools.Log(logOperation("importScene", parsedData ? parsedData.producer : "Unknown") + (SceneLoader.loggingLevel !== SceneLoader.MINIMAL_LOGGING ? log : ""));

+ 4 - 4
src/Loading/babylon.sceneLoader.ts

@@ -8,8 +8,8 @@
     export interface ISceneLoaderPlugin {
     export interface ISceneLoaderPlugin {
         name: string;
         name: string;
         extensions: string | ISceneLoaderPluginExtensions;
         extensions: string | ISceneLoaderPluginExtensions;
-        importMesh: (meshesNames: any, scene: Scene, data: any, rootUrl: string, meshes: AbstractMesh[], particleSystems: ParticleSystem[], skeletons: Skeleton[], onError: (message: string) => void) => boolean;
-        load: (scene: Scene, data: string, rootUrl: string, onError: (message: string) => void) => boolean;
+        importMesh: (meshesNames: any, scene: Scene, data: any, rootUrl: string, meshes: AbstractMesh[], particleSystems: ParticleSystem[], skeletons: Skeleton[], onError?: (message: string, exception?: any) => void) => boolean;
+        load: (scene: Scene, data: string, rootUrl: string, onError?: (message: string, exception?: any) => void) => boolean;
         canDirectLoad?: (data: string) => boolean;
         canDirectLoad?: (data: string) => boolean;
     }
     }
 
 
@@ -17,7 +17,7 @@
         name: string;
         name: string;
         extensions: string | ISceneLoaderPluginExtensions;
         extensions: string | ISceneLoaderPluginExtensions;
         importMeshAsync: (meshesNames: any, scene: Scene, data: any, rootUrl: string, onSuccess: (meshes: AbstractMesh[], particleSystems: ParticleSystem[], skeletons: Skeleton[]) => void, onProgress: (event: ProgressEvent) => void, onError: (message: string) => void) => void;
         importMeshAsync: (meshesNames: any, scene: Scene, data: any, rootUrl: string, onSuccess: (meshes: AbstractMesh[], particleSystems: ParticleSystem[], skeletons: Skeleton[]) => void, onProgress: (event: ProgressEvent) => void, onError: (message: string) => void) => void;
-        loadAsync: (scene: Scene, data: string, rootUrl: string, onSuccess: () => void, onProgress: (event: ProgressEvent) => void, onError: (message: string) => void) => void;
+        loadAsync: (scene: Scene, data: string, rootUrl: string, onSuccess: () => void, onProgress: (event: ProgressEvent) => void, onError: (message: string, exception?: any) => void) => void;
         canDirectLoad?: (data: string) => boolean;
         canDirectLoad?: (data: string) => boolean;
     }
     }
 
 
@@ -311,7 +311,7 @@
 
 
             var errorHandler = (message?: string, exception?: any) => {
             var errorHandler = (message?: string, exception?: any) => {
                 if (onError) {
                 if (onError) {
-                    onError(scene, "Unable to load from " + rootUrl + sceneFilename + (message ? ": " + message : ""));
+                    onError(scene, "Unable to load from " + rootUrl + sceneFilename + (message ? ": " + message : ""), exception);
                 }
                 }
                 scene._removePendingData(loadingToken);
                 scene._removePendingData(loadingToken);
                 scene.getEngine().hideLoadingUI();
                 scene.getEngine().hideLoadingUI();