Browse Source

Merge pull request #6105 from ddervisis/master

Fix EquiRectangularCubeTexture error handling and EquiRect./HDRCubeTexture caching problem
David Catuhe 6 years ago
parent
commit
485d473d4a

+ 4 - 2
dist/preview release/what's new.md

@@ -8,7 +8,7 @@
 - Added [support for AmmoJS](https://doc.babylonjs.com/how_to/using_the_physics_engine) as a physics plugin (Composite objects, motors, joints) ([TrevorDev](https://github.com/TrevorDev))
   - Added support for soft bodies, which are 3D softbody, 2D cloth and 1D rope, in Ammo physics plugin. [Doc](https://doc.babylonjs.com/how_to/soft_bodies) ([JohnK](https://github.com/BabylonJSGuide))
   - Added support for [Convex Hull Impostor][https://github.com/kripken/ammo.js/blob/master/bullet/src/BulletCollision/CollisionShapes/btConvexHullShape.h] using Ammo.js plugin ([MackeyK24](https://github.com/mackeyk24))
-  - Added AmmoJSPlugin scene file loader [MackeyK24](https://github.com/mackeyk24))  
+  - Added AmmoJSPlugin scene file loader [MackeyK24](https://github.com/mackeyk24))
 - Added support for [WebXR](https://doc.babylonjs.com/how_to/webxr) ([TrevorDev](https://github.com/TrevorDev))
   - Add customAnimationFrameRequester to allow sessions to hook into engine's render loop ([TrevorDev](https://github.com/TrevorDev))
   - camera customDefaultRenderTarget to allow cameras to render to a custom render target (eg. xr framebuffer) instead of the canvas ([TrevorDev](https://github.com/TrevorDev))
@@ -131,7 +131,7 @@
 - Observables can now make observers top or bottom priority ([TrevorDev](https://github.com/TrevorDev))
 - Mesh outline no longer is shown through the mesh when it's transparent ([TrevorDev](https://github.com/TrevorDev))
 - DeviceOrientationCamera will no longer be modified by mouse input if the orientation sensor is active ([TrevorDev](https://github.com/TrevorDev))
-- Added LoadScriptAsync tools helper function [MackeyK24](https://github.com/mackeyk24))  
+- Added LoadScriptAsync tools helper function [MackeyK24](https://github.com/mackeyk24))
 - Added customShaderNameResolve to PBRMaterialBase to allow subclasses to specify custom shader information [MackeyK24](https://github.com/mackeyk24))
 - Added PBRCustomMaterial to material library to allow easy subclassing of PBR materials [MackeyK24](https://github.com/mackeyk24))
 - Added `auto-exposure` support in `StandardRenderingPipeline` when `HDR` is enabled ([julien-moreau](https://github.com/julien-moreau))
@@ -225,6 +225,8 @@
 - Avoid exception when removing impostor during cannon world step ([TrevorDev](https://github.com/TrevorDev))
 - Fix ArcRotateCamera divide by zero error (when looking along up axis) in rebuildAnglesAndRadius ([sable](https://github.com/thscott))
 - Fix ArcRotateCamera rebuildAnglesAndRadius when upVector modified ([sable](https://github.com/thscott))
+- Fix code branch, that does not try to (re)load an `EquiRectangularCubeTexture`/`HDRCubeTexture` when the caching returns an empty or corrupt `InternalTexture` ([Dennis Dervisis](https://github.com/ddervisis))
+- Add error eventlistener (bubbling up the onError callback chain) in case an `EquiRectangularCubeTexture` cannot be loaded, because of a wrong path or IO problems ([Dennis Dervisis](https://github.com/ddervisis))
 
 ### Core Engine
 - Fixed a bug with `mesh.alwaysSelectAsActiveMesh` preventing layerMask to be taken in account ([Deltakosh](https://github.com/deltakosh))

+ 14 - 2
src/Materials/Textures/equiRectangularCubeTexture.ts

@@ -4,6 +4,7 @@ import { BaseTexture } from './baseTexture';
 import { Texture } from './texture';
 import { Scene } from "../../scene";
 import { Nullable } from "../../types";
+import { Tools } from '../../Misc/tools';
 
 /**
  * This represents a texture coming from an equirectangular image supported by the web browser canvas.
@@ -75,17 +76,23 @@ export class EquiRectangularCubeTexture extends BaseTexture {
 
         if (!this._texture) {
             if (!scene.useDelayedTextureLoading) {
-                this.loadImage(this.loadTexture.bind(this));
+                this.loadImage(this.loadTexture.bind(this), this._onError);
             } else {
                 this.delayLoadState = Engine.DELAYLOADSTATE_NOTLOADED;
             }
+        } else if (onLoad) {
+            if (this._texture.isReady) {
+                Tools.SetImmediate(() => onLoad());
+            } else {
+                this._texture.onLoadedObservable.add(onLoad);
+            }
         }
     }
 
     /**
      * Load the image data, by putting the image on a canvas and extracting its buffer.
      */
-    private loadImage(loadTextureCallback: () => void): void {
+    private loadImage(loadTextureCallback: () => void, onError: Nullable<(message?: string, exception?: any) => void>): void {
         const canvas = document.createElement('canvas');
         const image = new Image();
 
@@ -104,6 +111,11 @@ export class EquiRectangularCubeTexture extends BaseTexture {
             canvas.remove();
             loadTextureCallback();
         });
+        image.addEventListener('error', (error) => {
+            if (onError) {
+                onError(`${this.getClassName()} could not be loaded`, error);
+            }
+        });
         image.src = this.url;
     }
 

+ 7 - 0
src/Materials/Textures/hdrCubeTexture.ts

@@ -10,6 +10,7 @@ import { _DepthCullingState, _StencilState, _AlphaState } from "../../States/ind
 import { HDRTools } from "../../Misc/HighDynamicRange/hdr";
 import { CubeMapToSphericalPolynomialTools } from "../../Misc/HighDynamicRange/cubemapToSphericalPolynomial";
 import { _TypeStore } from '../../Misc/typeStore';
+import { Tools } from '../../Misc/tools';
 
 /**
  * This represents a texture coming from an HDR input.
@@ -140,6 +141,12 @@ export class HDRCubeTexture extends BaseTexture {
             } else {
                 this.delayLoadState = Engine.DELAYLOADSTATE_NOTLOADED;
             }
+        } else if (onLoad) {
+            if (this._texture.isReady) {
+                Tools.SetImmediate(() => onLoad());
+            } else {
+                this._texture.onLoadedObservable.add(onLoad);
+            }
         }
     }