Browse Source

Associated with #2982 (Holy cow!!)
Fix #3029

David Catuhe 7 years ago
parent
commit
4a513abe21
100 changed files with 13623 additions and 13308 deletions
  1. 3834 3834
      dist/preview release/babylon.d.ts
  2. 20 20
      dist/preview release/babylon.js
  3. 14 11
      dist/preview release/babylon.max.js
  4. 3834 3834
      dist/preview release/babylon.module.d.ts
  5. 20 20
      dist/preview release/babylon.worker.js
  6. 2527 2527
      dist/preview release/customConfigurations/minimalGLTFViewer/babylon.d.ts
  7. 21 21
      dist/preview release/customConfigurations/minimalGLTFViewer/babylon.js
  8. 26 18
      dist/preview release/customConfigurations/minimalGLTFViewer/babylon.max.js
  9. 2527 2527
      dist/preview release/customConfigurations/minimalGLTFViewer/babylon.module.d.ts
  10. 21 21
      dist/preview release/gui/babylon.gui.d.ts
  11. 56 16
      dist/preview release/gui/babylon.gui.js
  12. 3 3
      dist/preview release/gui/babylon.gui.min.js
  13. 21 21
      dist/preview release/gui/babylon.gui.module.d.ts
  14. 1 1
      dist/preview release/materialsLibrary/babylon.backgroundMaterial.d.ts
  15. 7 5
      dist/preview release/materialsLibrary/babylon.backgroundMaterial.js
  16. 1 1
      dist/preview release/materialsLibrary/babylon.backgroundMaterial.min.js
  17. 1 1
      dist/preview release/materialsLibrary/babylon.cellMaterial.d.ts
  18. 5 2
      dist/preview release/materialsLibrary/babylon.cellMaterial.js
  19. 1 1
      dist/preview release/materialsLibrary/babylon.cellMaterial.min.js
  20. 2 2
      dist/preview release/materialsLibrary/babylon.customMaterial.d.ts
  21. 9 3
      dist/preview release/materialsLibrary/babylon.customMaterial.js
  22. 2 2
      dist/preview release/materialsLibrary/babylon.customMaterial.min.js
  23. 4 4
      dist/preview release/materialsLibrary/babylon.fireMaterial.d.ts
  24. 8 3
      dist/preview release/materialsLibrary/babylon.fireMaterial.js
  25. 1 1
      dist/preview release/materialsLibrary/babylon.fireMaterial.min.js
  26. 1 1
      dist/preview release/materialsLibrary/babylon.furMaterial.d.ts
  27. 9 3
      dist/preview release/materialsLibrary/babylon.furMaterial.js
  28. 1 1
      dist/preview release/materialsLibrary/babylon.furMaterial.min.js
  29. 1 1
      dist/preview release/materialsLibrary/babylon.gradientMaterial.d.ts
  30. 7 4
      dist/preview release/materialsLibrary/babylon.gradientMaterial.js
  31. 1 1
      dist/preview release/materialsLibrary/babylon.gradientMaterial.min.js
  32. 5 2
      dist/preview release/materialsLibrary/babylon.gridMaterial.js
  33. 1 1
      dist/preview release/materialsLibrary/babylon.gridMaterial.min.js
  34. 1 1
      dist/preview release/materialsLibrary/babylon.lavaMaterial.d.ts
  35. 5 2
      dist/preview release/materialsLibrary/babylon.lavaMaterial.js
  36. 1 1
      dist/preview release/materialsLibrary/babylon.lavaMaterial.min.js
  37. 3 3
      dist/preview release/materialsLibrary/babylon.legacyPbrMaterial.d.ts
  38. 43 31
      dist/preview release/materialsLibrary/babylon.legacyPbrMaterial.js
  39. 2 2
      dist/preview release/materialsLibrary/babylon.legacyPbrMaterial.min.js
  40. 1 1
      dist/preview release/materialsLibrary/babylon.normalMaterial.d.ts
  41. 5 2
      dist/preview release/materialsLibrary/babylon.normalMaterial.js
  42. 1 1
      dist/preview release/materialsLibrary/babylon.normalMaterial.min.js
  43. 1 1
      dist/preview release/materialsLibrary/babylon.shadowOnlyMaterial.d.ts
  44. 5 2
      dist/preview release/materialsLibrary/babylon.shadowOnlyMaterial.js
  45. 1 1
      dist/preview release/materialsLibrary/babylon.shadowOnlyMaterial.min.js
  46. 1 1
      dist/preview release/materialsLibrary/babylon.simpleMaterial.d.ts
  47. 5 2
      dist/preview release/materialsLibrary/babylon.simpleMaterial.js
  48. 1 1
      dist/preview release/materialsLibrary/babylon.simpleMaterial.min.js
  49. 1 1
      dist/preview release/materialsLibrary/babylon.skyMaterial.d.ts
  50. 4 1
      dist/preview release/materialsLibrary/babylon.skyMaterial.js
  51. 1 1
      dist/preview release/materialsLibrary/babylon.skyMaterial.min.js
  52. 1 1
      dist/preview release/materialsLibrary/babylon.terrainMaterial.d.ts
  53. 5 2
      dist/preview release/materialsLibrary/babylon.terrainMaterial.js
  54. 1 1
      dist/preview release/materialsLibrary/babylon.terrainMaterial.min.js
  55. 1 1
      dist/preview release/materialsLibrary/babylon.triPlanarMaterial.d.ts
  56. 5 2
      dist/preview release/materialsLibrary/babylon.triPlanarMaterial.js
  57. 1 1
      dist/preview release/materialsLibrary/babylon.triPlanarMaterial.min.js
  58. 2 2
      dist/preview release/materialsLibrary/babylon.waterMaterial.d.ts
  59. 11 4
      dist/preview release/materialsLibrary/babylon.waterMaterial.js
  60. 1 1
      dist/preview release/materialsLibrary/babylon.waterMaterial.min.js
  61. 138 70
      dist/preview release/materialsLibrary/babylonjs.materials.js
  62. 9 9
      dist/preview release/materialsLibrary/babylonjs.materials.min.js
  63. 22 22
      dist/preview release/materialsLibrary/babylonjs.materials.module.d.ts
  64. 76 30
      gui/src/advancedDynamicTexture.ts
  65. 1 1
      gui/src/controls/colorpicker.ts
  66. 3 3
      gui/src/controls/container.ts
  67. 5 5
      gui/src/controls/control.ts
  68. 11 7
      gui/src/controls/image.ts
  69. 2 2
      gui/src/controls/inputText.ts
  70. 1 1
      gui/src/controls/line.ts
  71. 9 6
      gui/src/controls/virtualKeyboard.ts
  72. 1 1
      gui/src/math2D.ts
  73. 13 12
      materialsLibrary/src/background/babylon.backgroundMaterial.ts
  74. 7 4
      materialsLibrary/src/cell/babylon.cellMaterial.ts
  75. 15 9
      materialsLibrary/src/custom/babylon.customMaterial.ts
  76. 17 12
      materialsLibrary/src/fire/babylon.fireMaterial.ts
  77. 12 5
      materialsLibrary/src/fur/babylon.furMaterial.ts
  78. 10 6
      materialsLibrary/src/gradient/babylon.gradientMaterial.ts
  79. 5 2
      materialsLibrary/src/grid/babylon.gridmaterial.ts
  80. 8 4
      materialsLibrary/src/lava/babylon.lavaMaterial.ts
  81. 55 41
      materialsLibrary/src/legacyPBR/babylon.legacyPBRMaterial.ts
  82. 7 4
      materialsLibrary/src/normal/babylon.normalMaterial.ts
  83. 7 4
      materialsLibrary/src/shadowOnly/babylon.shadowOnlyMaterial.ts
  84. 7 4
      materialsLibrary/src/simple/babylon.simpleMaterial.ts
  85. 5 2
      materialsLibrary/src/sky/babylon.skyMaterial.ts
  86. 7 4
      materialsLibrary/src/terrain/babylon.terrainMaterial.ts
  87. 7 4
      materialsLibrary/src/triPlanar/babylon.triPlanarMaterial.ts
  88. 2 1
      materialsLibrary/src/tsconfig.json
  89. 17 9
      materialsLibrary/src/water/babylon.waterMaterial.ts
  90. 3 7
      src/Engine/babylon.engine.ts
  91. 2 2
      src/Layer/babylon.layer.ts
  92. 4 4
      src/Materials/PBR/babylon.pbrMaterial.ts
  93. 1 1
      src/Materials/Textures/babylon.dynamicTexture.ts
  94. 9 4
      src/Materials/babylon.imageProcessingConfiguration.ts
  95. 4 4
      src/Materials/babylon.standardMaterial.ts
  96. 4 4
      src/Physics/babylon.physicsImpostor.ts
  97. 4 4
      src/PostProcess/babylon.imageProcessingPostProcess.ts
  98. 6 6
      src/Sprites/babylon.spriteManager.ts
  99. 5 5
      src/States/babylon.alphaCullingState.ts
  100. 0 0
      src/States/babylon.depthCullingState.ts

File diff suppressed because it is too large
+ 3834 - 3834
dist/preview release/babylon.d.ts


File diff suppressed because it is too large
+ 20 - 20
dist/preview release/babylon.js


+ 14 - 11
dist/preview release/babylon.max.js

@@ -8597,12 +8597,8 @@ var BABYLON;
             }
             }
             // Constants
             // Constants
             this._gl.HALF_FLOAT_OES = 0x8D61; // Half floating-point type (16-bit).
             this._gl.HALF_FLOAT_OES = 0x8D61; // Half floating-point type (16-bit).
-            if (this._gl.RGBA16F !== 0x881A) {
-                this._gl.RGBA16F = 0x881A; // RGBA 16-bit floating-point color-renderable internal sized format.
-            }
-            if (this._gl.RGBA32F !== 0x8814) {
-                this._gl.RGBA32F = 0x8814; // RGBA 32-bit floating-point color-renderable internal sized format.
-            }
+            this._gl.RGBA16F = 0x881A; // RGBA 16-bit floating-point color-renderable internal sized format.
+            this._gl.RGBA32F = 0x8814; // RGBA 32-bit floating-point color-renderable internal sized format.
             this._gl.DEPTH24_STENCIL8 = 35056;
             this._gl.DEPTH24_STENCIL8 = 35056;
             // Extensions
             // Extensions
             this._caps.standardDerivatives = this._webGLVersion > 1 || (this._gl.getExtension('OES_standard_derivatives') !== null);
             this._caps.standardDerivatives = this._webGLVersion > 1 || (this._gl.getExtension('OES_standard_derivatives') !== null);
@@ -32123,7 +32119,13 @@ var BABYLON;
             defines.EXPOSURE = (this.exposure !== 1.0);
             defines.EXPOSURE = (this.exposure !== 1.0);
             defines.COLORCURVES = (this.colorCurvesEnabled && !!this.colorCurves);
             defines.COLORCURVES = (this.colorCurvesEnabled && !!this.colorCurves);
             defines.COLORGRADING = (this.colorGradingEnabled && !!this.colorGradingTexture);
             defines.COLORGRADING = (this.colorGradingEnabled && !!this.colorGradingTexture);
-            defines.COLORGRADING3D = defines.COLORGRADING && (this.colorGradingTexture.getScene().getEngine().webGLVersion > 1);
+            if (defines.COLORGRADING) {
+                var texture = this.colorGradingTexture;
+                defines.COLORGRADING3D = (texture.getScene().getEngine().webGLVersion > 1) ? true : false;
+            }
+            else {
+                defines.COLORGRADING3D = false;
+            }
             defines.SAMPLER3DGREENDEPTH = this.colorGradingWithGreenDepth;
             defines.SAMPLER3DGREENDEPTH = this.colorGradingWithGreenDepth;
             defines.SAMPLER3DBGRMAP = this.colorGradingBGR;
             defines.SAMPLER3DBGRMAP = this.colorGradingBGR;
             defines.IMAGEPROCESSINGPOSTPROCESS = this.applyByPostProcess;
             defines.IMAGEPROCESSINGPOSTPROCESS = this.applyByPostProcess;
@@ -32143,7 +32145,7 @@ var BABYLON;
         ImageProcessingConfiguration.prototype.bind = function (effect, aspectRatio) {
         ImageProcessingConfiguration.prototype.bind = function (effect, aspectRatio) {
             if (aspectRatio === void 0) { aspectRatio = 1; }
             if (aspectRatio === void 0) { aspectRatio = 1; }
             // Color Curves
             // Color Curves
-            if (this._colorCurvesEnabled) {
+            if (this._colorCurvesEnabled && this.colorCurves) {
                 BABYLON.ColorCurves.Bind(this.colorCurves, effect);
                 BABYLON.ColorCurves.Bind(this.colorCurves, effect);
             }
             }
             // Vignette
             // Vignette
@@ -42611,7 +42613,7 @@ var BABYLON;
             var min = BABYLON.Vector3.Zero();
             var min = BABYLON.Vector3.Zero();
             var max = BABYLON.Vector3.Zero();
             var max = BABYLON.Vector3.Zero();
             var distance = Number.MAX_VALUE;
             var distance = Number.MAX_VALUE;
-            var currentSprite;
+            var currentSprite = null;
             var cameraSpacePosition = BABYLON.Vector3.Zero();
             var cameraSpacePosition = BABYLON.Vector3.Zero();
             var cameraView = camera.getViewMatrix();
             var cameraView = camera.getViewMatrix();
             for (var index = 0; index < count; index++) {
             for (var index = 0; index < count; index++) {
@@ -50093,6 +50095,7 @@ var BABYLON;
     var DynamicTexture = /** @class */ (function (_super) {
     var DynamicTexture = /** @class */ (function (_super) {
         __extends(DynamicTexture, _super);
         __extends(DynamicTexture, _super);
         function DynamicTexture(name, options, scene, generateMipMaps, samplingMode, format) {
         function DynamicTexture(name, options, scene, generateMipMaps, samplingMode, format) {
+            if (scene === void 0) { scene = null; }
             if (samplingMode === void 0) { samplingMode = BABYLON.Texture.TRILINEAR_SAMPLINGMODE; }
             if (samplingMode === void 0) { samplingMode = BABYLON.Texture.TRILINEAR_SAMPLINGMODE; }
             if (format === void 0) { format = BABYLON.Engine.TEXTUREFORMAT_RGBA; }
             if (format === void 0) { format = BABYLON.Engine.TEXTUREFORMAT_RGBA; }
             var _this = _super.call(this, null, scene, !generateMipMaps, undefined, samplingMode, undefined, undefined, undefined, undefined, format) || this;
             var _this = _super.call(this, null, scene, !generateMipMaps, undefined, samplingMode, undefined, undefined, undefined, undefined, format) || this;
@@ -65541,7 +65544,7 @@ var BABYLON;
         });
         });
         Object.defineProperty(PhysicsImpostor.prototype, "parent", {
         Object.defineProperty(PhysicsImpostor.prototype, "parent", {
             get: function () {
             get: function () {
-                return !this._options.ignoreParent && this._parent;
+                return !this._options.ignoreParent && this._parent ? this._parent : null;
             },
             },
             set: function (value) {
             set: function (value) {
                 this._parent = value;
                 this._parent = value;
@@ -73564,7 +73567,7 @@ var BABYLON;
             this.texture = imgUrl ? new BABYLON.Texture(imgUrl, scene, true) : null;
             this.texture = imgUrl ? new BABYLON.Texture(imgUrl, scene, true) : null;
             this.isBackground = isBackground === undefined ? true : isBackground;
             this.isBackground = isBackground === undefined ? true : isBackground;
             this.color = color === undefined ? new BABYLON.Color4(1, 1, 1, 1) : color;
             this.color = color === undefined ? new BABYLON.Color4(1, 1, 1, 1) : color;
-            this._scene = scene || BABYLON.Engine.LastCreatedScene;
+            this._scene = (scene || BABYLON.Engine.LastCreatedScene);
             this._scene.layers.push(this);
             this._scene.layers.push(this);
             var engine = this._scene.getEngine();
             var engine = this._scene.getEngine();
             // VBO
             // VBO

File diff suppressed because it is too large
+ 3834 - 3834
dist/preview release/babylon.module.d.ts


File diff suppressed because it is too large
+ 20 - 20
dist/preview release/babylon.worker.js


File diff suppressed because it is too large
+ 2527 - 2527
dist/preview release/customConfigurations/minimalGLTFViewer/babylon.d.ts


File diff suppressed because it is too large
+ 21 - 21
dist/preview release/customConfigurations/minimalGLTFViewer/babylon.js


+ 26 - 18
dist/preview release/customConfigurations/minimalGLTFViewer/babylon.max.js

@@ -8597,12 +8597,8 @@ var BABYLON;
             }
             }
             // Constants
             // Constants
             this._gl.HALF_FLOAT_OES = 0x8D61; // Half floating-point type (16-bit).
             this._gl.HALF_FLOAT_OES = 0x8D61; // Half floating-point type (16-bit).
-            if (this._gl.RGBA16F !== 0x881A) {
-                this._gl.RGBA16F = 0x881A; // RGBA 16-bit floating-point color-renderable internal sized format.
-            }
-            if (this._gl.RGBA32F !== 0x8814) {
-                this._gl.RGBA32F = 0x8814; // RGBA 32-bit floating-point color-renderable internal sized format.
-            }
+            this._gl.RGBA16F = 0x881A; // RGBA 16-bit floating-point color-renderable internal sized format.
+            this._gl.RGBA32F = 0x8814; // RGBA 32-bit floating-point color-renderable internal sized format.
             this._gl.DEPTH24_STENCIL8 = 35056;
             this._gl.DEPTH24_STENCIL8 = 35056;
             // Extensions
             // Extensions
             this._caps.standardDerivatives = this._webGLVersion > 1 || (this._gl.getExtension('OES_standard_derivatives') !== null);
             this._caps.standardDerivatives = this._webGLVersion > 1 || (this._gl.getExtension('OES_standard_derivatives') !== null);
@@ -32123,7 +32119,13 @@ var BABYLON;
             defines.EXPOSURE = (this.exposure !== 1.0);
             defines.EXPOSURE = (this.exposure !== 1.0);
             defines.COLORCURVES = (this.colorCurvesEnabled && !!this.colorCurves);
             defines.COLORCURVES = (this.colorCurvesEnabled && !!this.colorCurves);
             defines.COLORGRADING = (this.colorGradingEnabled && !!this.colorGradingTexture);
             defines.COLORGRADING = (this.colorGradingEnabled && !!this.colorGradingTexture);
-            defines.COLORGRADING3D = defines.COLORGRADING && (this.colorGradingTexture.getScene().getEngine().webGLVersion > 1);
+            if (defines.COLORGRADING) {
+                var texture = this.colorGradingTexture;
+                defines.COLORGRADING3D = (texture.getScene().getEngine().webGLVersion > 1) ? true : false;
+            }
+            else {
+                defines.COLORGRADING3D = false;
+            }
             defines.SAMPLER3DGREENDEPTH = this.colorGradingWithGreenDepth;
             defines.SAMPLER3DGREENDEPTH = this.colorGradingWithGreenDepth;
             defines.SAMPLER3DBGRMAP = this.colorGradingBGR;
             defines.SAMPLER3DBGRMAP = this.colorGradingBGR;
             defines.IMAGEPROCESSINGPOSTPROCESS = this.applyByPostProcess;
             defines.IMAGEPROCESSINGPOSTPROCESS = this.applyByPostProcess;
@@ -32143,7 +32145,7 @@ var BABYLON;
         ImageProcessingConfiguration.prototype.bind = function (effect, aspectRatio) {
         ImageProcessingConfiguration.prototype.bind = function (effect, aspectRatio) {
             if (aspectRatio === void 0) { aspectRatio = 1; }
             if (aspectRatio === void 0) { aspectRatio = 1; }
             // Color Curves
             // Color Curves
-            if (this._colorCurvesEnabled) {
+            if (this._colorCurvesEnabled && this.colorCurves) {
                 BABYLON.ColorCurves.Bind(this.colorCurves, effect);
                 BABYLON.ColorCurves.Bind(this.colorCurves, effect);
             }
             }
             // Vignette
             // Vignette
@@ -42611,7 +42613,7 @@ var BABYLON;
             var min = BABYLON.Vector3.Zero();
             var min = BABYLON.Vector3.Zero();
             var max = BABYLON.Vector3.Zero();
             var max = BABYLON.Vector3.Zero();
             var distance = Number.MAX_VALUE;
             var distance = Number.MAX_VALUE;
-            var currentSprite;
+            var currentSprite = null;
             var cameraSpacePosition = BABYLON.Vector3.Zero();
             var cameraSpacePosition = BABYLON.Vector3.Zero();
             var cameraView = camera.getViewMatrix();
             var cameraView = camera.getViewMatrix();
             for (var index = 0; index < count; index++) {
             for (var index = 0; index < count; index++) {
@@ -50093,6 +50095,7 @@ var BABYLON;
     var DynamicTexture = /** @class */ (function (_super) {
     var DynamicTexture = /** @class */ (function (_super) {
         __extends(DynamicTexture, _super);
         __extends(DynamicTexture, _super);
         function DynamicTexture(name, options, scene, generateMipMaps, samplingMode, format) {
         function DynamicTexture(name, options, scene, generateMipMaps, samplingMode, format) {
+            if (scene === void 0) { scene = null; }
             if (samplingMode === void 0) { samplingMode = BABYLON.Texture.TRILINEAR_SAMPLINGMODE; }
             if (samplingMode === void 0) { samplingMode = BABYLON.Texture.TRILINEAR_SAMPLINGMODE; }
             if (format === void 0) { format = BABYLON.Engine.TEXTUREFORMAT_RGBA; }
             if (format === void 0) { format = BABYLON.Engine.TEXTUREFORMAT_RGBA; }
             var _this = _super.call(this, null, scene, !generateMipMaps, undefined, samplingMode, undefined, undefined, undefined, undefined, format) || this;
             var _this = _super.call(this, null, scene, !generateMipMaps, undefined, samplingMode, undefined, undefined, undefined, undefined, format) || this;
@@ -65541,7 +65544,7 @@ var BABYLON;
         });
         });
         Object.defineProperty(PhysicsImpostor.prototype, "parent", {
         Object.defineProperty(PhysicsImpostor.prototype, "parent", {
             get: function () {
             get: function () {
-                return !this._options.ignoreParent && this._parent;
+                return !this._options.ignoreParent && this._parent ? this._parent : null;
             },
             },
             set: function (value) {
             set: function (value) {
                 this._parent = value;
                 this._parent = value;
@@ -73564,7 +73567,7 @@ var BABYLON;
             this.texture = imgUrl ? new BABYLON.Texture(imgUrl, scene, true) : null;
             this.texture = imgUrl ? new BABYLON.Texture(imgUrl, scene, true) : null;
             this.isBackground = isBackground === undefined ? true : isBackground;
             this.isBackground = isBackground === undefined ? true : isBackground;
             this.color = color === undefined ? new BABYLON.Color4(1, 1, 1, 1) : color;
             this.color = color === undefined ? new BABYLON.Color4(1, 1, 1, 1) : color;
-            this._scene = scene || BABYLON.Engine.LastCreatedScene;
+            this._scene = (scene || BABYLON.Engine.LastCreatedScene);
             this._scene.layers.push(this);
             this._scene.layers.push(this);
             var engine = this._scene.getEngine();
             var engine = this._scene.getEngine();
             // VBO
             // VBO
@@ -74669,9 +74672,9 @@ var BABYLON;
                 var attribs = [BABYLON.VertexBuffer.PositionKind, BABYLON.VertexBuffer.NormalKind];
                 var attribs = [BABYLON.VertexBuffer.PositionKind, BABYLON.VertexBuffer.NormalKind];
                 // Defines
                 // Defines
                 var join = defines.toString();
                 var join = defines.toString();
-                subMesh.setEffect(scene.getEngine().createEffect("grid", attribs, ["projection", "worldView", "mainColor", "lineColor", "gridControl", "gridOffset", "vFogInfos", "vFogColor", "world", "view"], [], join, null, this.onCompiled, this.onError), defines);
+                subMesh.setEffect(scene.getEngine().createEffect("grid", attribs, ["projection", "worldView", "mainColor", "lineColor", "gridControl", "gridOffset", "vFogInfos", "vFogColor", "world", "view"], [], join, undefined, this.onCompiled, this.onError), defines);
             }
             }
-            if (!subMesh.effect.isReady()) {
+            if (!subMesh.effect || !subMesh.effect.isReady()) {
                 return false;
                 return false;
             }
             }
             this._renderId = scene.getRenderId();
             this._renderId = scene.getRenderId();
@@ -74685,6 +74688,9 @@ var BABYLON;
                 return;
                 return;
             }
             }
             var effect = subMesh.effect;
             var effect = subMesh.effect;
+            if (!effect) {
+                return;
+            }
             this._activeEffect = effect;
             this._activeEffect = effect;
             // Matrices
             // Matrices
             this.bindOnlyWorldMatrix(world);
             this.bindOnlyWorldMatrix(world);
@@ -75051,7 +75057,7 @@ var BABYLON;
              * Sets the Color Grading 2D Lookup Texture.
              * Sets the Color Grading 2D Lookup Texture.
              */
              */
             set: function (value) {
             set: function (value) {
-                this._imageProcessingConfiguration.colorGradingTexture = value;
+                this.imageProcessingConfiguration.colorGradingTexture = value;
             },
             },
             enumerable: true,
             enumerable: true,
             configurable: true
             configurable: true
@@ -75064,7 +75070,7 @@ var BABYLON;
              * corresponding to low luminance, medium luminance, and high luminance areas respectively.
              * corresponding to low luminance, medium luminance, and high luminance areas respectively.
              */
              */
             get: function () {
             get: function () {
-                return this._imageProcessingConfiguration.colorCurves;
+                return this.imageProcessingConfiguration.colorCurves;
             },
             },
             /**
             /**
              * The color grading curves provide additional color adjustmnent that is applied after any color grading transform (3D LUT).
              * The color grading curves provide additional color adjustmnent that is applied after any color grading transform (3D LUT).
@@ -75073,7 +75079,7 @@ var BABYLON;
              * corresponding to low luminance, medium luminance, and high luminance areas respectively.
              * corresponding to low luminance, medium luminance, and high luminance areas respectively.
              */
              */
             set: function (value) {
             set: function (value) {
-                this._imageProcessingConfiguration.colorCurves = value;
+                this.imageProcessingConfiguration.colorCurves = value;
             },
             },
             enumerable: true,
             enumerable: true,
             configurable: true
             configurable: true
@@ -75254,7 +75260,7 @@ var BABYLON;
                 }, engine), defines);
                 }, engine), defines);
                 this.buildUniformLayout();
                 this.buildUniformLayout();
             }
             }
-            if (!subMesh.effect.isReady()) {
+            if (!subMesh.effect || !subMesh.effect.isReady()) {
                 return false;
                 return false;
             }
             }
             defines._renderId = scene.getRenderId();
             defines._renderId = scene.getRenderId();
@@ -75309,6 +75315,9 @@ var BABYLON;
                 return;
                 return;
             }
             }
             var effect = subMesh.effect;
             var effect = subMesh.effect;
+            if (!effect) {
+                return;
+            }
             this._activeEffect = effect;
             this._activeEffect = effect;
             // Matrices
             // Matrices
             this.bindOnlyWorldMatrix(world);
             this.bindOnlyWorldMatrix(world);
@@ -75381,7 +75390,6 @@ var BABYLON;
             }
             }
             this._uniformBuffer.update();
             this._uniformBuffer.update();
             this._afterBind(mesh);
             this._afterBind(mesh);
-            scene = null;
         };
         };
         /**
         /**
          * Dispose the material.
          * Dispose the material.

File diff suppressed because it is too large
+ 2527 - 2527
dist/preview release/customConfigurations/minimalGLTFViewer/babylon.module.d.ts


+ 21 - 21
dist/preview release/gui/babylon.gui.d.ts

@@ -16,11 +16,11 @@ declare module BABYLON.GUI {
         private _background;
         private _background;
         _rootContainer: Container;
         _rootContainer: Container;
         _lastPickedControl: Control;
         _lastPickedControl: Control;
-        _lastControlOver: Control;
-        _lastControlDown: Control;
-        _capturingControl: Control;
+        _lastControlOver: Nullable<Control>;
+        _lastControlDown: Nullable<Control>;
+        _capturingControl: Nullable<Control>;
         _shouldBlockPointer: boolean;
         _shouldBlockPointer: boolean;
-        _layerToDispose: Layer;
+        _layerToDispose: Nullable<Layer>;
         _linkedControls: Control[];
         _linkedControls: Control[];
         private _isFullscreen;
         private _isFullscreen;
         private _fullscreenViewport;
         private _fullscreenViewport;
@@ -33,10 +33,10 @@ declare module BABYLON.GUI {
         idealWidth: number;
         idealWidth: number;
         idealHeight: number;
         idealHeight: number;
         renderAtIdealSize: boolean;
         renderAtIdealSize: boolean;
-        readonly layer: Layer;
+        readonly layer: Nullable<Layer>;
         readonly rootContainer: Container;
         readonly rootContainer: Container;
-        focusedControl: IFocusableControl;
-        constructor(name: string, width: number, height: number, scene: Scene, generateMipMaps?: boolean, samplingMode?: number);
+        focusedControl: Nullable<IFocusableControl>;
+        constructor(name: string, width: number, height: number, scene: Nullable<Scene>, generateMipMaps?: boolean, samplingMode?: number);
         executeOnAllControls(func: (control: Control) => void, container?: Container): void;
         executeOnAllControls(func: (control: Control) => void, container?: Container): void;
         markAsDirty(): void;
         markAsDirty(): void;
         addControl(control: Control): AdvancedDynamicTexture;
         addControl(control: Control): AdvancedDynamicTexture;
@@ -53,7 +53,7 @@ declare module BABYLON.GUI {
         private _manageFocus();
         private _manageFocus();
         private _attachToOnPointerOut(scene);
         private _attachToOnPointerOut(scene);
         static CreateForMesh(mesh: AbstractMesh, width?: number, height?: number, supportPointerMove?: boolean): AdvancedDynamicTexture;
         static CreateForMesh(mesh: AbstractMesh, width?: number, height?: number, supportPointerMove?: boolean): AdvancedDynamicTexture;
-        static CreateFullscreenUI(name: string, foreground?: boolean, scene?: Scene): AdvancedDynamicTexture;
+        static CreateFullscreenUI(name: string, foreground?: boolean, scene?: Nullable<Scene>): AdvancedDynamicTexture;
     }
     }
 }
 }
 
 
@@ -96,7 +96,7 @@ declare module BABYLON.GUI {
         private static _TempCompose0;
         private static _TempCompose0;
         private static _TempCompose1;
         private static _TempCompose1;
         private static _TempCompose2;
         private static _TempCompose2;
-        static ComposeToRef(tx: number, ty: number, angle: number, scaleX: number, scaleY: number, parentMatrix: Matrix2D, result: Matrix2D): void;
+        static ComposeToRef(tx: number, ty: number, angle: number, scaleX: number, scaleY: number, parentMatrix: Nullable<Matrix2D>, result: Matrix2D): void;
     }
     }
 }
 }
 
 
@@ -130,9 +130,9 @@ declare module BABYLON.GUI {
         private _alpha;
         private _alpha;
         private _alphaSet;
         private _alphaSet;
         private _zIndex;
         private _zIndex;
-        _root: Container;
+        _root: Nullable<Container>;
         _host: AdvancedDynamicTexture;
         _host: AdvancedDynamicTexture;
-        parent: Container;
+        parent: Nullable<Container>;
         _currentMeasure: Measure;
         _currentMeasure: Measure;
         private _fontFamily;
         private _fontFamily;
         private _fontStyle;
         private _fontStyle;
@@ -168,7 +168,7 @@ declare module BABYLON.GUI {
         private _cachedOffsetX;
         private _cachedOffsetX;
         private _cachedOffsetY;
         private _cachedOffsetY;
         private _isVisible;
         private _isVisible;
-        _linkedMesh: AbstractMesh;
+        _linkedMesh: Nullable<AbstractMesh>;
         private _fontSet;
         private _fontSet;
         private _dummyVector2;
         private _dummyVector2;
         private _downCount;
         private _downCount;
@@ -260,12 +260,12 @@ declare module BABYLON.GUI {
         getLocalCoordinatesToRef(globalCoordinates: Vector2, result: Vector2): Control;
         getLocalCoordinatesToRef(globalCoordinates: Vector2, result: Vector2): Control;
         getParentLocalCoordinates(globalCoordinates: Vector2): Vector2;
         getParentLocalCoordinates(globalCoordinates: Vector2): Vector2;
         moveToVector3(position: Vector3, scene: Scene): void;
         moveToVector3(position: Vector3, scene: Scene): void;
-        linkWithMesh(mesh: AbstractMesh): void;
+        linkWithMesh(mesh: Nullable<AbstractMesh>): void;
         _moveToProjectedPosition(projectedPosition: Vector3): void;
         _moveToProjectedPosition(projectedPosition: Vector3): void;
         _markMatrixAsDirty(): void;
         _markMatrixAsDirty(): void;
         _markAsDirty(): void;
         _markAsDirty(): void;
         _markAllAsDirty(): void;
         _markAllAsDirty(): void;
-        _link(root: Container, host: AdvancedDynamicTexture): void;
+        _link(root: Nullable<Container>, host: AdvancedDynamicTexture): void;
         protected _transform(context: CanvasRenderingContext2D): void;
         protected _transform(context: CanvasRenderingContext2D): void;
         protected _applyStates(context: CanvasRenderingContext2D): void;
         protected _applyStates(context: CanvasRenderingContext2D): void;
         protected _processMeasures(parentMeasure: Measure, context: CanvasRenderingContext2D): boolean;
         protected _processMeasures(parentMeasure: Measure, context: CanvasRenderingContext2D): boolean;
@@ -323,8 +323,8 @@ declare module BABYLON.GUI {
         readonly children: Control[];
         readonly children: Control[];
         constructor(name?: string);
         constructor(name?: string);
         protected _getTypeName(): string;
         protected _getTypeName(): string;
-        getChildByName(name: string): Control;
-        getChildByType(name: string, type: string): Control;
+        getChildByName(name: string): Nullable<Control>;
+        getChildByType(name: string, type: string): Nullable<Control>;
         containsControl(control: Control): boolean;
         containsControl(control: Control): boolean;
         addControl(control: Control): Container;
         addControl(control: Control): Container;
         removeControl(control: Control): Container;
         removeControl(control: Control): Container;
@@ -332,7 +332,7 @@ declare module BABYLON.GUI {
         _markMatrixAsDirty(): void;
         _markMatrixAsDirty(): void;
         _markAllAsDirty(): void;
         _markAllAsDirty(): void;
         protected _localDraw(context: CanvasRenderingContext2D): void;
         protected _localDraw(context: CanvasRenderingContext2D): void;
-        _link(root: Container, host: AdvancedDynamicTexture): void;
+        _link(root: Nullable<Container>, host: AdvancedDynamicTexture): void;
         _draw(parentMeasure: Measure, context: CanvasRenderingContext2D): void;
         _draw(parentMeasure: Measure, context: CanvasRenderingContext2D): void;
         _processPicking(x: number, y: number, type: number, buttonIndex: number): boolean;
         _processPicking(x: number, y: number, type: number, buttonIndex: number): boolean;
         protected _clipForChildren(context: CanvasRenderingContext2D): void;
         protected _clipForChildren(context: CanvasRenderingContext2D): void;
@@ -551,8 +551,8 @@ declare module BABYLON.GUI {
         stretch: number;
         stretch: number;
         domImage: HTMLImageElement;
         domImage: HTMLImageElement;
         private _onImageLoaded();
         private _onImageLoaded();
-        source: string;
-        constructor(name?: string, url?: string);
+        source: Nullable<string>;
+        constructor(name?: string, url?: Nullable<string>);
         protected _getTypeName(): string;
         protected _getTypeName(): string;
         synchronizeSizeWithContent(): void;
         synchronizeSizeWithContent(): void;
         _draw(parentMeasure: Measure, context: CanvasRenderingContext2D): void;
         _draw(parentMeasure: Measure, context: CanvasRenderingContext2D): void;
@@ -699,13 +699,13 @@ declare module BABYLON.GUI {
         defaultButtonColor: string;
         defaultButtonColor: string;
         defaultButtonBackground: string;
         defaultButtonBackground: string;
         protected _getTypeName(): string;
         protected _getTypeName(): string;
-        private _createKey(key, propertySet?);
+        private _createKey(key, propertySet);
         addKeysRow(keys: Array<string>, propertySets?: Array<KeyPropertySet>): void;
         addKeysRow(keys: Array<string>, propertySets?: Array<KeyPropertySet>): void;
         private _connectedInputText;
         private _connectedInputText;
         private _onFocusObserver;
         private _onFocusObserver;
         private _onBlurObserver;
         private _onBlurObserver;
         private _onKeyPressObserver;
         private _onKeyPressObserver;
-        readonly connectedInputText: InputText;
+        readonly connectedInputText: Nullable<InputText>;
         connect(input: InputText): void;
         connect(input: InputText): void;
         disconnect(): void;
         disconnect(): void;
         static CreateDefaultLayout(): VirtualKeyboard;
         static CreateDefaultLayout(): VirtualKeyboard;

+ 56 - 16
dist/preview release/gui/babylon.gui.js

@@ -39,8 +39,12 @@ var BABYLON;
                 _this._idealHeight = 0;
                 _this._idealHeight = 0;
                 _this._renderAtIdealSize = false;
                 _this._renderAtIdealSize = false;
                 _this._blockNextFocusCheck = false;
                 _this._blockNextFocusCheck = false;
-                _this._renderObserver = _this.getScene().onBeforeCameraRenderObservable.add(function (camera) { return _this._checkUpdate(camera); });
-                _this._preKeyboardObserver = _this.getScene().onPreKeyboardObservable.add(function (info) {
+                scene = _this.getScene();
+                if (!scene || !_this._texture) {
+                    return _this;
+                }
+                _this._renderObserver = scene.onBeforeCameraRenderObservable.add(function (camera) { return _this._checkUpdate(camera); });
+                _this._preKeyboardObserver = scene.onPreKeyboardObservable.add(function (info) {
                     if (!_this._focusedControl) {
                     if (!_this._focusedControl) {
                         return;
                         return;
                     }
                     }
@@ -52,7 +56,7 @@ var BABYLON;
                 _this._rootContainer._link(null, _this);
                 _this._rootContainer._link(null, _this);
                 _this.hasAlpha = true;
                 _this.hasAlpha = true;
                 if (!width || !height) {
                 if (!width || !height) {
-                    _this._resizeObserver = _this.getScene().getEngine().onResizeObservable.add(function () { return _this._onResize(); });
+                    _this._resizeObserver = scene.getEngine().onResizeObservable.add(function () { return _this._onResize(); });
                     _this._onResize();
                     _this._onResize();
                 }
                 }
                 _this._texture.isReady = true;
                 _this._texture.isReady = true;
@@ -174,18 +178,22 @@ var BABYLON;
                 return this;
                 return this;
             };
             };
             AdvancedDynamicTexture.prototype.dispose = function () {
             AdvancedDynamicTexture.prototype.dispose = function () {
-                this.getScene().onBeforeCameraRenderObservable.remove(this._renderObserver);
+                var scene = this.getScene();
+                if (!scene) {
+                    return;
+                }
+                scene.onBeforeCameraRenderObservable.remove(this._renderObserver);
                 if (this._resizeObserver) {
                 if (this._resizeObserver) {
-                    this.getScene().getEngine().onResizeObservable.remove(this._resizeObserver);
+                    scene.getEngine().onResizeObservable.remove(this._resizeObserver);
                 }
                 }
                 if (this._pointerMoveObserver) {
                 if (this._pointerMoveObserver) {
-                    this.getScene().onPrePointerObservable.remove(this._pointerMoveObserver);
+                    scene.onPrePointerObservable.remove(this._pointerMoveObserver);
                 }
                 }
                 if (this._pointerObserver) {
                 if (this._pointerObserver) {
-                    this.getScene().onPointerObservable.remove(this._pointerObserver);
+                    scene.onPointerObservable.remove(this._pointerObserver);
                 }
                 }
                 if (this._canvasPointerOutObserver) {
                 if (this._canvasPointerOutObserver) {
-                    this.getScene().getEngine().onCanvasPointerOutObservable.remove(this._canvasPointerOutObserver);
+                    scene.getEngine().onCanvasPointerOutObservable.remove(this._canvasPointerOutObserver);
                 }
                 }
                 if (this._layerToDispose) {
                 if (this._layerToDispose) {
                     this._layerToDispose.texture = null;
                     this._layerToDispose.texture = null;
@@ -196,8 +204,12 @@ var BABYLON;
                 _super.prototype.dispose.call(this);
                 _super.prototype.dispose.call(this);
             };
             };
             AdvancedDynamicTexture.prototype._onResize = function () {
             AdvancedDynamicTexture.prototype._onResize = function () {
+                var scene = this.getScene();
+                if (!scene) {
+                    return;
+                }
                 // Check size
                 // Check size
-                var engine = this.getScene().getEngine();
+                var engine = scene.getEngine();
                 var textureSize = this.getSize();
                 var textureSize = this.getSize();
                 var renderWidth = engine.getRenderWidth();
                 var renderWidth = engine.getRenderWidth();
                 var renderHeight = engine.getRenderHeight();
                 var renderHeight = engine.getRenderHeight();
@@ -231,6 +243,9 @@ var BABYLON;
                 }
                 }
                 if (this._isFullscreen && this._linkedControls.length) {
                 if (this._isFullscreen && this._linkedControls.length) {
                     var scene = this.getScene();
                     var scene = this.getScene();
+                    if (!scene) {
+                        return;
+                    }
                     var globalViewport = this._getGlobalViewport(scene);
                     var globalViewport = this._getGlobalViewport(scene);
                     for (var _i = 0, _a = this._linkedControls; _i < _a.length; _i++) {
                     for (var _i = 0, _a = this._linkedControls; _i < _a.length; _i++) {
                         var control = _a[_i];
                         var control = _a[_i];
@@ -282,6 +297,9 @@ var BABYLON;
             };
             };
             AdvancedDynamicTexture.prototype._doPicking = function (x, y, type, buttonIndex) {
             AdvancedDynamicTexture.prototype._doPicking = function (x, y, type, buttonIndex) {
                 var scene = this.getScene();
                 var scene = this.getScene();
+                if (!scene) {
+                    return;
+                }
                 var engine = scene.getEngine();
                 var engine = scene.getEngine();
                 var textureSize = this.getSize();
                 var textureSize = this.getSize();
                 if (this._isFullscreen) {
                 if (this._isFullscreen) {
@@ -305,13 +323,22 @@ var BABYLON;
             AdvancedDynamicTexture.prototype.attach = function () {
             AdvancedDynamicTexture.prototype.attach = function () {
                 var _this = this;
                 var _this = this;
                 var scene = this.getScene();
                 var scene = this.getScene();
+                if (!scene) {
+                    return;
+                }
                 this._pointerMoveObserver = scene.onPrePointerObservable.add(function (pi, state) {
                 this._pointerMoveObserver = scene.onPrePointerObservable.add(function (pi, state) {
                     if (pi.type !== BABYLON.PointerEventTypes.POINTERMOVE
                     if (pi.type !== BABYLON.PointerEventTypes.POINTERMOVE
                         && pi.type !== BABYLON.PointerEventTypes.POINTERUP
                         && pi.type !== BABYLON.PointerEventTypes.POINTERUP
                         && pi.type !== BABYLON.PointerEventTypes.POINTERDOWN) {
                         && pi.type !== BABYLON.PointerEventTypes.POINTERDOWN) {
                         return;
                         return;
                     }
                     }
+                    if (!scene) {
+                        return;
+                    }
                     var camera = scene.cameraToUseForPointers || scene.activeCamera;
                     var camera = scene.cameraToUseForPointers || scene.activeCamera;
+                    if (!camera) {
+                        return;
+                    }
                     var engine = scene.getEngine();
                     var engine = scene.getEngine();
                     var viewport = camera.viewport;
                     var viewport = camera.viewport;
                     var x = (scene.pointerX / engine.getHardwareScalingLevel() - viewport.x * engine.getRenderWidth()) / viewport.width;
                     var x = (scene.pointerX / engine.getHardwareScalingLevel() - viewport.x * engine.getRenderWidth()) / viewport.width;
@@ -326,16 +353,21 @@ var BABYLON;
                 var _this = this;
                 var _this = this;
                 if (supportPointerMove === void 0) { supportPointerMove = true; }
                 if (supportPointerMove === void 0) { supportPointerMove = true; }
                 var scene = this.getScene();
                 var scene = this.getScene();
+                if (!scene) {
+                    return;
+                }
                 this._pointerObserver = scene.onPointerObservable.add(function (pi, state) {
                 this._pointerObserver = scene.onPointerObservable.add(function (pi, state) {
                     if (pi.type !== BABYLON.PointerEventTypes.POINTERMOVE
                     if (pi.type !== BABYLON.PointerEventTypes.POINTERMOVE
                         && pi.type !== BABYLON.PointerEventTypes.POINTERUP
                         && pi.type !== BABYLON.PointerEventTypes.POINTERUP
                         && pi.type !== BABYLON.PointerEventTypes.POINTERDOWN) {
                         && pi.type !== BABYLON.PointerEventTypes.POINTERDOWN) {
                         return;
                         return;
                     }
                     }
-                    if (pi.pickInfo.hit && pi.pickInfo.pickedMesh === mesh) {
+                    if (pi.pickInfo && pi.pickInfo.hit && pi.pickInfo.pickedMesh === mesh) {
                         var uv = pi.pickInfo.getTextureCoordinates();
                         var uv = pi.pickInfo.getTextureCoordinates();
-                        var size = _this.getSize();
-                        _this._doPicking(uv.x * size.width, (1.0 - uv.y) * size.height, pi.type, pi.event.button);
+                        if (uv) {
+                            var size = _this.getSize();
+                            _this._doPicking(uv.x * size.width, (1.0 - uv.y) * size.height, pi.type, pi.event.button);
+                        }
                     }
                     }
                     else if (pi.type === BABYLON.PointerEventTypes.POINTERUP) {
                     else if (pi.type === BABYLON.PointerEventTypes.POINTERUP) {
                         if (_this._lastControlDown) {
                         if (_this._lastControlDown) {
@@ -3149,6 +3181,7 @@ var BABYLON;
         var Image = /** @class */ (function (_super) {
         var Image = /** @class */ (function (_super) {
             __extends(Image, _super);
             __extends(Image, _super);
             function Image(name, url) {
             function Image(name, url) {
+                if (url === void 0) { url = null; }
                 var _this = _super.call(this, name) || this;
                 var _this = _super.call(this, name) || this;
                 _this.name = name;
                 _this.name = name;
                 _this._loaded = false;
                 _this._loaded = false;
@@ -3288,8 +3321,10 @@ var BABYLON;
                     this._domImage.onload = function () {
                     this._domImage.onload = function () {
                         _this._onImageLoaded();
                         _this._onImageLoaded();
                     };
                     };
-                    this._domImage.crossOrigin = "anonymous";
-                    this._domImage.src = value;
+                    if (value) {
+                        this._domImage.crossOrigin = "anonymous";
+                        this._domImage.src = value;
+                    }
                 },
                 },
                 enumerable: true,
                 enumerable: true,
                 configurable: true
                 configurable: true
@@ -3333,8 +3368,10 @@ var BABYLON;
                                 if (this._autoScale) {
                                 if (this._autoScale) {
                                     this.synchronizeSizeWithContent();
                                     this.synchronizeSizeWithContent();
                                 }
                                 }
-                                this._root.width = this.width;
-                                this._root.height = this.height;
+                                if (this._root) {
+                                    this._root.width = this.width;
+                                    this._root.height = this.height;
+                                }
                                 break;
                                 break;
                         }
                         }
                     }
                     }
@@ -4350,6 +4387,9 @@ var BABYLON;
                     _this.isVisible = false;
                     _this.isVisible = false;
                 });
                 });
                 this._onKeyPressObserver = this.onKeyPressObservable.add(function (key) {
                 this._onKeyPressObserver = this.onKeyPressObservable.add(function (key) {
+                    if (!_this._connectedInputText) {
+                        return;
+                    }
                     switch (key) {
                     switch (key) {
                         case "\u2190":
                         case "\u2190":
                             _this._connectedInputText.processKey(8);
                             _this._connectedInputText.processKey(8);

File diff suppressed because it is too large
+ 3 - 3
dist/preview release/gui/babylon.gui.min.js


+ 21 - 21
dist/preview release/gui/babylon.gui.module.d.ts

@@ -21,11 +21,11 @@ declare module BABYLON.GUI {
         private _background;
         private _background;
         _rootContainer: Container;
         _rootContainer: Container;
         _lastPickedControl: Control;
         _lastPickedControl: Control;
-        _lastControlOver: Control;
-        _lastControlDown: Control;
-        _capturingControl: Control;
+        _lastControlOver: Nullable<Control>;
+        _lastControlDown: Nullable<Control>;
+        _capturingControl: Nullable<Control>;
         _shouldBlockPointer: boolean;
         _shouldBlockPointer: boolean;
-        _layerToDispose: Layer;
+        _layerToDispose: Nullable<Layer>;
         _linkedControls: Control[];
         _linkedControls: Control[];
         private _isFullscreen;
         private _isFullscreen;
         private _fullscreenViewport;
         private _fullscreenViewport;
@@ -38,10 +38,10 @@ declare module BABYLON.GUI {
         idealWidth: number;
         idealWidth: number;
         idealHeight: number;
         idealHeight: number;
         renderAtIdealSize: boolean;
         renderAtIdealSize: boolean;
-        readonly layer: Layer;
+        readonly layer: Nullable<Layer>;
         readonly rootContainer: Container;
         readonly rootContainer: Container;
-        focusedControl: IFocusableControl;
-        constructor(name: string, width: number, height: number, scene: Scene, generateMipMaps?: boolean, samplingMode?: number);
+        focusedControl: Nullable<IFocusableControl>;
+        constructor(name: string, width: number, height: number, scene: Nullable<Scene>, generateMipMaps?: boolean, samplingMode?: number);
         executeOnAllControls(func: (control: Control) => void, container?: Container): void;
         executeOnAllControls(func: (control: Control) => void, container?: Container): void;
         markAsDirty(): void;
         markAsDirty(): void;
         addControl(control: Control): AdvancedDynamicTexture;
         addControl(control: Control): AdvancedDynamicTexture;
@@ -58,7 +58,7 @@ declare module BABYLON.GUI {
         private _manageFocus();
         private _manageFocus();
         private _attachToOnPointerOut(scene);
         private _attachToOnPointerOut(scene);
         static CreateForMesh(mesh: AbstractMesh, width?: number, height?: number, supportPointerMove?: boolean): AdvancedDynamicTexture;
         static CreateForMesh(mesh: AbstractMesh, width?: number, height?: number, supportPointerMove?: boolean): AdvancedDynamicTexture;
-        static CreateFullscreenUI(name: string, foreground?: boolean, scene?: Scene): AdvancedDynamicTexture;
+        static CreateFullscreenUI(name: string, foreground?: boolean, scene?: Nullable<Scene>): AdvancedDynamicTexture;
     }
     }
 }
 }
 
 
@@ -101,7 +101,7 @@ declare module BABYLON.GUI {
         private static _TempCompose0;
         private static _TempCompose0;
         private static _TempCompose1;
         private static _TempCompose1;
         private static _TempCompose2;
         private static _TempCompose2;
-        static ComposeToRef(tx: number, ty: number, angle: number, scaleX: number, scaleY: number, parentMatrix: Matrix2D, result: Matrix2D): void;
+        static ComposeToRef(tx: number, ty: number, angle: number, scaleX: number, scaleY: number, parentMatrix: Nullable<Matrix2D>, result: Matrix2D): void;
     }
     }
 }
 }
 
 
@@ -135,9 +135,9 @@ declare module BABYLON.GUI {
         private _alpha;
         private _alpha;
         private _alphaSet;
         private _alphaSet;
         private _zIndex;
         private _zIndex;
-        _root: Container;
+        _root: Nullable<Container>;
         _host: AdvancedDynamicTexture;
         _host: AdvancedDynamicTexture;
-        parent: Container;
+        parent: Nullable<Container>;
         _currentMeasure: Measure;
         _currentMeasure: Measure;
         private _fontFamily;
         private _fontFamily;
         private _fontStyle;
         private _fontStyle;
@@ -173,7 +173,7 @@ declare module BABYLON.GUI {
         private _cachedOffsetX;
         private _cachedOffsetX;
         private _cachedOffsetY;
         private _cachedOffsetY;
         private _isVisible;
         private _isVisible;
-        _linkedMesh: AbstractMesh;
+        _linkedMesh: Nullable<AbstractMesh>;
         private _fontSet;
         private _fontSet;
         private _dummyVector2;
         private _dummyVector2;
         private _downCount;
         private _downCount;
@@ -265,12 +265,12 @@ declare module BABYLON.GUI {
         getLocalCoordinatesToRef(globalCoordinates: Vector2, result: Vector2): Control;
         getLocalCoordinatesToRef(globalCoordinates: Vector2, result: Vector2): Control;
         getParentLocalCoordinates(globalCoordinates: Vector2): Vector2;
         getParentLocalCoordinates(globalCoordinates: Vector2): Vector2;
         moveToVector3(position: Vector3, scene: Scene): void;
         moveToVector3(position: Vector3, scene: Scene): void;
-        linkWithMesh(mesh: AbstractMesh): void;
+        linkWithMesh(mesh: Nullable<AbstractMesh>): void;
         _moveToProjectedPosition(projectedPosition: Vector3): void;
         _moveToProjectedPosition(projectedPosition: Vector3): void;
         _markMatrixAsDirty(): void;
         _markMatrixAsDirty(): void;
         _markAsDirty(): void;
         _markAsDirty(): void;
         _markAllAsDirty(): void;
         _markAllAsDirty(): void;
-        _link(root: Container, host: AdvancedDynamicTexture): void;
+        _link(root: Nullable<Container>, host: AdvancedDynamicTexture): void;
         protected _transform(context: CanvasRenderingContext2D): void;
         protected _transform(context: CanvasRenderingContext2D): void;
         protected _applyStates(context: CanvasRenderingContext2D): void;
         protected _applyStates(context: CanvasRenderingContext2D): void;
         protected _processMeasures(parentMeasure: Measure, context: CanvasRenderingContext2D): boolean;
         protected _processMeasures(parentMeasure: Measure, context: CanvasRenderingContext2D): boolean;
@@ -328,8 +328,8 @@ declare module BABYLON.GUI {
         readonly children: Control[];
         readonly children: Control[];
         constructor(name?: string);
         constructor(name?: string);
         protected _getTypeName(): string;
         protected _getTypeName(): string;
-        getChildByName(name: string): Control;
-        getChildByType(name: string, type: string): Control;
+        getChildByName(name: string): Nullable<Control>;
+        getChildByType(name: string, type: string): Nullable<Control>;
         containsControl(control: Control): boolean;
         containsControl(control: Control): boolean;
         addControl(control: Control): Container;
         addControl(control: Control): Container;
         removeControl(control: Control): Container;
         removeControl(control: Control): Container;
@@ -337,7 +337,7 @@ declare module BABYLON.GUI {
         _markMatrixAsDirty(): void;
         _markMatrixAsDirty(): void;
         _markAllAsDirty(): void;
         _markAllAsDirty(): void;
         protected _localDraw(context: CanvasRenderingContext2D): void;
         protected _localDraw(context: CanvasRenderingContext2D): void;
-        _link(root: Container, host: AdvancedDynamicTexture): void;
+        _link(root: Nullable<Container>, host: AdvancedDynamicTexture): void;
         _draw(parentMeasure: Measure, context: CanvasRenderingContext2D): void;
         _draw(parentMeasure: Measure, context: CanvasRenderingContext2D): void;
         _processPicking(x: number, y: number, type: number, buttonIndex: number): boolean;
         _processPicking(x: number, y: number, type: number, buttonIndex: number): boolean;
         protected _clipForChildren(context: CanvasRenderingContext2D): void;
         protected _clipForChildren(context: CanvasRenderingContext2D): void;
@@ -556,8 +556,8 @@ declare module BABYLON.GUI {
         stretch: number;
         stretch: number;
         domImage: HTMLImageElement;
         domImage: HTMLImageElement;
         private _onImageLoaded();
         private _onImageLoaded();
-        source: string;
-        constructor(name?: string, url?: string);
+        source: Nullable<string>;
+        constructor(name?: string, url?: Nullable<string>);
         protected _getTypeName(): string;
         protected _getTypeName(): string;
         synchronizeSizeWithContent(): void;
         synchronizeSizeWithContent(): void;
         _draw(parentMeasure: Measure, context: CanvasRenderingContext2D): void;
         _draw(parentMeasure: Measure, context: CanvasRenderingContext2D): void;
@@ -704,13 +704,13 @@ declare module BABYLON.GUI {
         defaultButtonColor: string;
         defaultButtonColor: string;
         defaultButtonBackground: string;
         defaultButtonBackground: string;
         protected _getTypeName(): string;
         protected _getTypeName(): string;
-        private _createKey(key, propertySet?);
+        private _createKey(key, propertySet);
         addKeysRow(keys: Array<string>, propertySets?: Array<KeyPropertySet>): void;
         addKeysRow(keys: Array<string>, propertySets?: Array<KeyPropertySet>): void;
         private _connectedInputText;
         private _connectedInputText;
         private _onFocusObserver;
         private _onFocusObserver;
         private _onBlurObserver;
         private _onBlurObserver;
         private _onKeyPressObserver;
         private _onKeyPressObserver;
-        readonly connectedInputText: InputText;
+        readonly connectedInputText: Nullable<InputText>;
         connect(input: InputText): void;
         connect(input: InputText): void;
         disconnect(): void;
         disconnect(): void;
         static CreateDefaultLayout(): VirtualKeyboard;
         static CreateDefaultLayout(): VirtualKeyboard;

+ 1 - 1
dist/preview release/materialsLibrary/babylon.backgroundMaterial.d.ts

@@ -108,7 +108,7 @@ declare namespace BABYLON {
          *
          *
          * If sets to null, the scene one is in use.
          * If sets to null, the scene one is in use.
          */
          */
-        imageProcessingConfiguration: ImageProcessingConfiguration;
+        imageProcessingConfiguration: Nullable<ImageProcessingConfiguration>;
         /**
         /**
          * Gets wether the color curves effect is enabled.
          * Gets wether the color curves effect is enabled.
          */
          */

+ 7 - 5
dist/preview release/materialsLibrary/babylon.backgroundMaterial.js

@@ -301,7 +301,7 @@ var BABYLON;
              * Sets the Color Grading 2D Lookup Texture.
              * Sets the Color Grading 2D Lookup Texture.
              */
              */
             set: function (value) {
             set: function (value) {
-                this._imageProcessingConfiguration.colorGradingTexture = value;
+                this.imageProcessingConfiguration.colorGradingTexture = value;
             },
             },
             enumerable: true,
             enumerable: true,
             configurable: true
             configurable: true
@@ -314,7 +314,7 @@ var BABYLON;
              * corresponding to low luminance, medium luminance, and high luminance areas respectively.
              * corresponding to low luminance, medium luminance, and high luminance areas respectively.
              */
              */
             get: function () {
             get: function () {
-                return this._imageProcessingConfiguration.colorCurves;
+                return this.imageProcessingConfiguration.colorCurves;
             },
             },
             /**
             /**
              * The color grading curves provide additional color adjustmnent that is applied after any color grading transform (3D LUT).
              * The color grading curves provide additional color adjustmnent that is applied after any color grading transform (3D LUT).
@@ -323,7 +323,7 @@ var BABYLON;
              * corresponding to low luminance, medium luminance, and high luminance areas respectively.
              * corresponding to low luminance, medium luminance, and high luminance areas respectively.
              */
              */
             set: function (value) {
             set: function (value) {
-                this._imageProcessingConfiguration.colorCurves = value;
+                this.imageProcessingConfiguration.colorCurves = value;
             },
             },
             enumerable: true,
             enumerable: true,
             configurable: true
             configurable: true
@@ -504,7 +504,7 @@ var BABYLON;
                 }, engine), defines);
                 }, engine), defines);
                 this.buildUniformLayout();
                 this.buildUniformLayout();
             }
             }
-            if (!subMesh.effect.isReady()) {
+            if (!subMesh.effect || !subMesh.effect.isReady()) {
                 return false;
                 return false;
             }
             }
             defines._renderId = scene.getRenderId();
             defines._renderId = scene.getRenderId();
@@ -559,6 +559,9 @@ var BABYLON;
                 return;
                 return;
             }
             }
             var effect = subMesh.effect;
             var effect = subMesh.effect;
+            if (!effect) {
+                return;
+            }
             this._activeEffect = effect;
             this._activeEffect = effect;
             // Matrices
             // Matrices
             this.bindOnlyWorldMatrix(world);
             this.bindOnlyWorldMatrix(world);
@@ -631,7 +634,6 @@ var BABYLON;
             }
             }
             this._uniformBuffer.update();
             this._uniformBuffer.update();
             this._afterBind(mesh);
             this._afterBind(mesh);
-            scene = null;
         };
         };
         /**
         /**
          * Dispose the material.
          * Dispose the material.

File diff suppressed because it is too large
+ 1 - 1
dist/preview release/materialsLibrary/babylon.backgroundMaterial.min.js


+ 1 - 1
dist/preview release/materialsLibrary/babylon.cellMaterial.d.ts

@@ -14,7 +14,7 @@ declare module BABYLON {
         constructor(name: string, scene: Scene);
         constructor(name: string, scene: Scene);
         needAlphaBlending(): boolean;
         needAlphaBlending(): boolean;
         needAlphaTesting(): boolean;
         needAlphaTesting(): boolean;
-        getAlphaTestTexture(): BaseTexture;
+        getAlphaTestTexture(): Nullable<BaseTexture>;
         isReadyForSubMesh(mesh: AbstractMesh, subMesh: SubMesh, useInstances?: boolean): boolean;
         isReadyForSubMesh(mesh: AbstractMesh, subMesh: SubMesh, useInstances?: boolean): boolean;
         bindForSubMesh(world: Matrix, mesh: Mesh, subMesh: SubMesh): void;
         bindForSubMesh(world: Matrix, mesh: Mesh, subMesh: SubMesh): void;
         getAnimatables(): IAnimatable[];
         getAnimatables(): IAnimatable[];

+ 5 - 2
dist/preview release/materialsLibrary/babylon.cellMaterial.js

@@ -102,7 +102,7 @@ var BABYLON;
             // Lights
             // Lights
             defines._needNormals = BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights, this._disableLighting);
             defines._needNormals = BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights, this._disableLighting);
             // Values that need to be evaluated on every frame
             // Values that need to be evaluated on every frame
-            BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances);
+            BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false);
             // Attribs
             // Attribs
             BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true);
             BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true);
             // Get correct effect      
             // Get correct effect      
@@ -163,7 +163,7 @@ var BABYLON;
                     indexParameters: { maxSimultaneousLights: this.maxSimultaneousLights - 1 }
                     indexParameters: { maxSimultaneousLights: this.maxSimultaneousLights - 1 }
                 }, engine), defines);
                 }, engine), defines);
             }
             }
-            if (!subMesh.effect.isReady()) {
+            if (!subMesh.effect || !subMesh.effect.isReady()) {
                 return false;
                 return false;
             }
             }
             this._renderId = scene.getRenderId();
             this._renderId = scene.getRenderId();
@@ -177,6 +177,9 @@ var BABYLON;
                 return;
                 return;
             }
             }
             var effect = subMesh.effect;
             var effect = subMesh.effect;
+            if (!effect) {
+                return;
+            }
             this._activeEffect = effect;
             this._activeEffect = effect;
             // Matrices        
             // Matrices        
             this.bindOnlyWorldMatrix(world);
             this.bindOnlyWorldMatrix(world);

File diff suppressed because it is too large
+ 1 - 1
dist/preview release/materialsLibrary/babylon.cellMaterial.min.js


+ 2 - 2
dist/preview release/materialsLibrary/babylon.customMaterial.d.ts

@@ -175,7 +175,7 @@ declare module BABYLON {
          * Attaches a new image processing configuration to the Standard Material.
          * Attaches a new image processing configuration to the Standard Material.
          * @param configuration
          * @param configuration
          */
          */
-        protected _attachImageProcessingConfiguration(configuration: ImageProcessingConfiguration): void;
+        protected _attachImageProcessingConfiguration(configuration: Nullable<ImageProcessingConfiguration>): void;
         /**
         /**
          * Gets wether the color curves effect is enabled.
          * Gets wether the color curves effect is enabled.
          */
          */
@@ -221,7 +221,7 @@ declare module BABYLON {
         /**
         /**
          * Sets the Color Grading 2D Lookup Texture.
          * Sets the Color Grading 2D Lookup Texture.
          */
          */
-        cameraColorGradingTexture: BaseTexture;
+        cameraColorGradingTexture: Nullable<BaseTexture>;
         customShaderNameResolve: (shaderName: string, uniforms: string[], uniformBuffers: string[], samplers: string[], defines: StandardMaterialDefines_OldVer) => string;
         customShaderNameResolve: (shaderName: string, uniforms: string[], uniformBuffers: string[], samplers: string[], defines: StandardMaterialDefines_OldVer) => string;
         protected _renderTargets: SmartArray<RenderTargetTexture>;
         protected _renderTargets: SmartArray<RenderTargetTexture>;
         protected _worldViewProjectionMatrix: Matrix;
         protected _worldViewProjectionMatrix: Matrix;

+ 9 - 3
dist/preview release/materialsLibrary/babylon.customMaterial.js

@@ -564,7 +564,7 @@ var BABYLON;
             // Attribs
             // Attribs
             BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true, true);
             BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true, true);
             // Values that need to be evaluated on every frame
             // Values that need to be evaluated on every frame
-            BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances);
+            BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false);
             // Get correct effect      
             // Get correct effect      
             if (defines.isDirty) {
             if (defines.isDirty) {
                 defines.markAsProcessed();
                 defines.markAsProcessed();
@@ -671,7 +671,7 @@ var BABYLON;
                 }, engine), defines);
                 }, engine), defines);
                 this.buildUniformLayout();
                 this.buildUniformLayout();
             }
             }
-            if (!subMesh.effect.isReady()) {
+            if (!subMesh.effect || !subMesh.effect.isReady()) {
                 return false;
                 return false;
             }
             }
             defines._renderId = scene.getRenderId();
             defines._renderId = scene.getRenderId();
@@ -732,6 +732,9 @@ var BABYLON;
                 return;
                 return;
             }
             }
             var effect = subMesh.effect;
             var effect = subMesh.effect;
+            if (!effect) {
+                return;
+            }
             this._activeEffect = effect;
             this._activeEffect = effect;
             // Matrices        
             // Matrices        
             this.bindOnlyWorldMatrix(world);
             this.bindOnlyWorldMatrix(world);
@@ -1951,11 +1954,14 @@ vColor=color;\n\
                 return this._createdShaderName;
                 return this._createdShaderName;
             this._isCreatedShader = false;
             this._isCreatedShader = false;
             CustomMaterial.ShaderIndexer++;
             CustomMaterial.ShaderIndexer++;
-            var name = name + "custom_" + CustomMaterial.ShaderIndexer;
+            var name = "custom_" + CustomMaterial.ShaderIndexer;
             this.ReviewUniform("uniform", uniforms);
             this.ReviewUniform("uniform", uniforms);
             this.ReviewUniform("sampler", samplers);
             this.ReviewUniform("sampler", samplers);
             var fn_afterBind = this._afterBind;
             var fn_afterBind = this._afterBind;
             this._afterBind = function (m, e) {
             this._afterBind = function (m, e) {
+                if (!e) {
+                    return;
+                }
                 _this.AttachAfterBind(m, e);
                 _this.AttachAfterBind(m, e);
                 try {
                 try {
                     fn_afterBind(m, e);
                     fn_afterBind(m, e);

File diff suppressed because it is too large
+ 2 - 2
dist/preview release/materialsLibrary/babylon.customMaterial.min.js


+ 4 - 4
dist/preview release/materialsLibrary/babylon.fireMaterial.d.ts

@@ -2,11 +2,11 @@
 declare module BABYLON {
 declare module BABYLON {
     class FireMaterial extends PushMaterial {
     class FireMaterial extends PushMaterial {
         private _diffuseTexture;
         private _diffuseTexture;
-        diffuseTexture: BaseTexture;
+        diffuseTexture: Nullable<BaseTexture>;
         private _distortionTexture;
         private _distortionTexture;
-        distortionTexture: BaseTexture;
+        distortionTexture: Nullable<BaseTexture>;
         private _opacityTexture;
         private _opacityTexture;
-        opacityTexture: BaseTexture;
+        opacityTexture: Nullable<BaseTexture>;
         diffuseColor: Color3;
         diffuseColor: Color3;
         speed: number;
         speed: number;
         private _scaledDiffuse;
         private _scaledDiffuse;
@@ -15,7 +15,7 @@ declare module BABYLON {
         constructor(name: string, scene: Scene);
         constructor(name: string, scene: Scene);
         needAlphaBlending(): boolean;
         needAlphaBlending(): boolean;
         needAlphaTesting(): boolean;
         needAlphaTesting(): boolean;
-        getAlphaTestTexture(): BaseTexture;
+        getAlphaTestTexture(): Nullable<BaseTexture>;
         isReadyForSubMesh(mesh: AbstractMesh, subMesh: SubMesh, useInstances?: boolean): boolean;
         isReadyForSubMesh(mesh: AbstractMesh, subMesh: SubMesh, useInstances?: boolean): boolean;
         bindForSubMesh(world: Matrix, mesh: Mesh, subMesh: SubMesh): void;
         bindForSubMesh(world: Matrix, mesh: Mesh, subMesh: SubMesh): void;
         getAnimatables(): IAnimatable[];
         getAnimatables(): IAnimatable[];

+ 8 - 3
dist/preview release/materialsLibrary/babylon.fireMaterial.js

@@ -94,7 +94,7 @@ var BABYLON;
                 defines.FOG = (scene.fogEnabled && mesh.applyFog && scene.fogMode !== BABYLON.Scene.FOGMODE_NONE && this.fogEnabled);
                 defines.FOG = (scene.fogEnabled && mesh.applyFog && scene.fogMode !== BABYLON.Scene.FOGMODE_NONE && this.fogEnabled);
             }
             }
             // Values that need to be evaluated on every frame
             // Values that need to be evaluated on every frame
-            BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances);
+            BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false);
             // Attribs
             // Attribs
             BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, false, true);
             BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, false, true);
             // Get correct effect      
             // Get correct effect      
@@ -140,10 +140,12 @@ var BABYLON;
                     defines: join,
                     defines: join,
                     fallbacks: fallbacks,
                     fallbacks: fallbacks,
                     onCompiled: this.onCompiled,
                     onCompiled: this.onCompiled,
-                    onError: this.onError
+                    onError: this.onError,
+                    indexParameters: null,
+                    maxSimultaneousLights: 4
                 }, engine), defines);
                 }, engine), defines);
             }
             }
-            if (!subMesh.effect.isReady()) {
+            if (!subMesh.effect || !subMesh.effect.isReady()) {
                 return false;
                 return false;
             }
             }
             this._renderId = scene.getRenderId();
             this._renderId = scene.getRenderId();
@@ -157,6 +159,9 @@ var BABYLON;
                 return;
                 return;
             }
             }
             var effect = subMesh.effect;
             var effect = subMesh.effect;
+            if (!effect) {
+                return;
+            }
             this._activeEffect = effect;
             this._activeEffect = effect;
             // Matrices
             // Matrices
             this.bindOnlyWorldMatrix(world);
             this.bindOnlyWorldMatrix(world);

File diff suppressed because it is too large
+ 1 - 1
dist/preview release/materialsLibrary/babylon.fireMaterial.min.js


+ 1 - 1
dist/preview release/materialsLibrary/babylon.furMaterial.d.ts

@@ -27,7 +27,7 @@ declare module BABYLON {
         furTime: number;
         furTime: number;
         needAlphaBlending(): boolean;
         needAlphaBlending(): boolean;
         needAlphaTesting(): boolean;
         needAlphaTesting(): boolean;
-        getAlphaTestTexture(): BaseTexture;
+        getAlphaTestTexture(): Nullable<BaseTexture>;
         updateFur(): void;
         updateFur(): void;
         isReadyForSubMesh(mesh: AbstractMesh, subMesh: SubMesh, useInstances?: boolean): boolean;
         isReadyForSubMesh(mesh: AbstractMesh, subMesh: SubMesh, useInstances?: boolean): boolean;
         bindForSubMesh(world: Matrix, mesh: Mesh, subMesh: SubMesh): void;
         bindForSubMesh(world: Matrix, mesh: Mesh, subMesh: SubMesh): void;

+ 9 - 3
dist/preview release/materialsLibrary/babylon.furMaterial.js

@@ -147,7 +147,7 @@ var BABYLON;
             // Lights
             // Lights
             defines._needNormals = BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights, this._disableLighting);
             defines._needNormals = BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights, this._disableLighting);
             // Values that need to be evaluated on every frame
             // Values that need to be evaluated on every frame
-            BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances);
+            BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false);
             // Attribs
             // Attribs
             BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true);
             BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true);
             // Get correct effect      
             // Get correct effect      
@@ -212,7 +212,7 @@ var BABYLON;
                     indexParameters: { maxSimultaneousLights: this.maxSimultaneousLights }
                     indexParameters: { maxSimultaneousLights: this.maxSimultaneousLights }
                 }, engine), defines);
                 }, engine), defines);
             }
             }
-            if (!subMesh.effect.isReady()) {
+            if (!subMesh.effect || !subMesh.effect.isReady()) {
                 return false;
                 return false;
             }
             }
             this._renderId = scene.getRenderId();
             this._renderId = scene.getRenderId();
@@ -226,6 +226,9 @@ var BABYLON;
                 return;
                 return;
             }
             }
             var effect = subMesh.effect;
             var effect = subMesh.effect;
+            if (!effect) {
+                return;
+            }
             this._activeEffect = effect;
             this._activeEffect = effect;
             // Matrices        
             // Matrices        
             this.bindOnlyWorldMatrix(world);
             this.bindOnlyWorldMatrix(world);
@@ -312,7 +315,10 @@ var BABYLON;
             }
             }
             if (this._meshes) {
             if (this._meshes) {
                 for (var i = 1; i < this._meshes.length; i++) {
                 for (var i = 1; i < this._meshes.length; i++) {
-                    this._meshes[i].material.dispose(forceDisposeEffect);
+                    var mat = this._meshes[i].material;
+                    if (mat) {
+                        mat.dispose(forceDisposeEffect);
+                    }
                     this._meshes[i].dispose();
                     this._meshes[i].dispose();
                 }
                 }
             }
             }

File diff suppressed because it is too large
+ 1 - 1
dist/preview release/materialsLibrary/babylon.furMaterial.min.js


+ 1 - 1
dist/preview release/materialsLibrary/babylon.gradientMaterial.d.ts

@@ -15,7 +15,7 @@ declare module BABYLON {
         constructor(name: string, scene: Scene);
         constructor(name: string, scene: Scene);
         needAlphaBlending(): boolean;
         needAlphaBlending(): boolean;
         needAlphaTesting(): boolean;
         needAlphaTesting(): boolean;
-        getAlphaTestTexture(): BaseTexture;
+        getAlphaTestTexture(): Nullable<BaseTexture>;
         isReadyForSubMesh(mesh: AbstractMesh, subMesh: SubMesh, useInstances?: boolean): boolean;
         isReadyForSubMesh(mesh: AbstractMesh, subMesh: SubMesh, useInstances?: boolean): boolean;
         bindForSubMesh(world: Matrix, mesh: Mesh, subMesh: SubMesh): void;
         bindForSubMesh(world: Matrix, mesh: Mesh, subMesh: SubMesh): void;
         getAnimatables(): IAnimatable[];
         getAnimatables(): IAnimatable[];

+ 7 - 4
dist/preview release/materialsLibrary/babylon.gradientMaterial.js

@@ -118,7 +118,7 @@ var BABYLON;
                 }
                 }
             }
             }
             var engine = scene.getEngine();
             var engine = scene.getEngine();
-            BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances);
+            BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false);
             BABYLON.MaterialHelper.PrepareDefinesForMisc(mesh, scene, false, this.pointsCloud, this.fogEnabled, defines);
             BABYLON.MaterialHelper.PrepareDefinesForMisc(mesh, scene, false, this.pointsCloud, this.fogEnabled, defines);
             defines._needNormals = BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights);
             defines._needNormals = BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights);
             // Attribs
             // Attribs
@@ -183,7 +183,7 @@ var BABYLON;
                     indexParameters: { maxSimultaneousLights: 4 }
                     indexParameters: { maxSimultaneousLights: 4 }
                 }, engine), defines);
                 }, engine), defines);
             }
             }
-            if (!subMesh.effect.isReady()) {
+            if (!subMesh.effect || !subMesh.effect.isReady()) {
                 return false;
                 return false;
             }
             }
             this._renderId = scene.getRenderId();
             this._renderId = scene.getRenderId();
@@ -197,15 +197,18 @@ var BABYLON;
                 return;
                 return;
             }
             }
             var effect = subMesh.effect;
             var effect = subMesh.effect;
+            if (!effect) {
+                return;
+            }
             this._activeEffect = effect;
             this._activeEffect = effect;
             // Matrices        
             // Matrices        
             this.bindOnlyWorldMatrix(world);
             this.bindOnlyWorldMatrix(world);
             this._activeEffect.setMatrix("viewProjection", scene.getTransformMatrix());
             this._activeEffect.setMatrix("viewProjection", scene.getTransformMatrix());
             // Bones
             // Bones
-            BABYLON.MaterialHelper.BindBonesParameters(mesh, this._effect);
+            BABYLON.MaterialHelper.BindBonesParameters(mesh, effect);
             if (this._mustRebind(scene, effect)) {
             if (this._mustRebind(scene, effect)) {
                 // Clip plane
                 // Clip plane
-                BABYLON.MaterialHelper.BindClipPlane(this._effect, scene);
+                BABYLON.MaterialHelper.BindClipPlane(effect, scene);
                 // Point size
                 // Point size
                 if (this.pointsCloud) {
                 if (this.pointsCloud) {
                     this._activeEffect.setFloat("pointSize", this.pointSize);
                     this._activeEffect.setFloat("pointSize", this.pointSize);

File diff suppressed because it is too large
+ 1 - 1
dist/preview release/materialsLibrary/babylon.gradientMaterial.min.js


+ 5 - 2
dist/preview release/materialsLibrary/babylon.gridMaterial.js

@@ -116,9 +116,9 @@ var BABYLON;
                 var attribs = [BABYLON.VertexBuffer.PositionKind, BABYLON.VertexBuffer.NormalKind];
                 var attribs = [BABYLON.VertexBuffer.PositionKind, BABYLON.VertexBuffer.NormalKind];
                 // Defines
                 // Defines
                 var join = defines.toString();
                 var join = defines.toString();
-                subMesh.setEffect(scene.getEngine().createEffect("grid", attribs, ["projection", "worldView", "mainColor", "lineColor", "gridControl", "gridOffset", "vFogInfos", "vFogColor", "world", "view"], [], join, null, this.onCompiled, this.onError), defines);
+                subMesh.setEffect(scene.getEngine().createEffect("grid", attribs, ["projection", "worldView", "mainColor", "lineColor", "gridControl", "gridOffset", "vFogInfos", "vFogColor", "world", "view"], [], join, undefined, this.onCompiled, this.onError), defines);
             }
             }
-            if (!subMesh.effect.isReady()) {
+            if (!subMesh.effect || !subMesh.effect.isReady()) {
                 return false;
                 return false;
             }
             }
             this._renderId = scene.getRenderId();
             this._renderId = scene.getRenderId();
@@ -132,6 +132,9 @@ var BABYLON;
                 return;
                 return;
             }
             }
             var effect = subMesh.effect;
             var effect = subMesh.effect;
+            if (!effect) {
+                return;
+            }
             this._activeEffect = effect;
             this._activeEffect = effect;
             // Matrices
             // Matrices
             this.bindOnlyWorldMatrix(world);
             this.bindOnlyWorldMatrix(world);

File diff suppressed because it is too large
+ 1 - 1
dist/preview release/materialsLibrary/babylon.gridMaterial.min.js


+ 1 - 1
dist/preview release/materialsLibrary/babylon.lavaMaterial.d.ts

@@ -20,7 +20,7 @@ declare module BABYLON {
         constructor(name: string, scene: Scene);
         constructor(name: string, scene: Scene);
         needAlphaBlending(): boolean;
         needAlphaBlending(): boolean;
         needAlphaTesting(): boolean;
         needAlphaTesting(): boolean;
-        getAlphaTestTexture(): BaseTexture;
+        getAlphaTestTexture(): Nullable<BaseTexture>;
         isReadyForSubMesh(mesh: AbstractMesh, subMesh: SubMesh, useInstances?: boolean): boolean;
         isReadyForSubMesh(mesh: AbstractMesh, subMesh: SubMesh, useInstances?: boolean): boolean;
         bindForSubMesh(world: Matrix, mesh: Mesh, subMesh: SubMesh): void;
         bindForSubMesh(world: Matrix, mesh: Mesh, subMesh: SubMesh): void;
         getAnimatables(): IAnimatable[];
         getAnimatables(): IAnimatable[];

+ 5 - 2
dist/preview release/materialsLibrary/babylon.lavaMaterial.js

@@ -135,7 +135,7 @@ var BABYLON;
             // Lights
             // Lights
             defines._needNormals = BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights, this._disableLighting);
             defines._needNormals = BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights, this._disableLighting);
             // Values that need to be evaluated on every frame
             // Values that need to be evaluated on every frame
-            BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances);
+            BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false);
             // Attribs
             // Attribs
             BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true);
             BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true);
             // Get correct effect      
             // Get correct effect      
@@ -201,7 +201,7 @@ var BABYLON;
                     indexParameters: { maxSimultaneousLights: this.maxSimultaneousLights }
                     indexParameters: { maxSimultaneousLights: this.maxSimultaneousLights }
                 }, engine), defines);
                 }, engine), defines);
             }
             }
-            if (!subMesh.effect.isReady()) {
+            if (!subMesh.effect || !subMesh.effect.isReady()) {
                 return false;
                 return false;
             }
             }
             this._renderId = scene.getRenderId();
             this._renderId = scene.getRenderId();
@@ -215,6 +215,9 @@ var BABYLON;
                 return;
                 return;
             }
             }
             var effect = subMesh.effect;
             var effect = subMesh.effect;
+            if (!effect) {
+                return;
+            }
             this._activeEffect = effect;
             this._activeEffect = effect;
             // Matrices        
             // Matrices        
             this.bindOnlyWorldMatrix(world);
             this.bindOnlyWorldMatrix(world);

File diff suppressed because it is too large
+ 1 - 1
dist/preview release/materialsLibrary/babylon.lavaMaterial.min.js


+ 3 - 3
dist/preview release/materialsLibrary/babylon.legacyPbrMaterial.d.ts

@@ -59,14 +59,14 @@ declare module BABYLON {
          * Color Grading 2D Lookup Texture.
          * Color Grading 2D Lookup Texture.
          * This allows special effects like sepia, black and white to sixties rendering style.
          * This allows special effects like sepia, black and white to sixties rendering style.
          */
          */
-        cameraColorGradingTexture: BaseTexture;
+        cameraColorGradingTexture: Nullable<BaseTexture>;
         /**
         /**
          * The color grading curves provide additional color adjustmnent that is applied after any color grading transform (3D LUT).
          * The color grading curves provide additional color adjustmnent that is applied after any color grading transform (3D LUT).
          * They allow basic adjustment of saturation and small exposure adjustments, along with color filter tinting to provide white balance adjustment or more stylistic effects.
          * They allow basic adjustment of saturation and small exposure adjustments, along with color filter tinting to provide white balance adjustment or more stylistic effects.
          * These are similar to controls found in many professional imaging or colorist software. The global controls are applied to the entire image. For advanced tuning, extra controls are provided to adjust the shadow, midtone and highlight areas of the image;
          * These are similar to controls found in many professional imaging or colorist software. The global controls are applied to the entire image. For advanced tuning, extra controls are provided to adjust the shadow, midtone and highlight areas of the image;
          * corresponding to low luminance, medium luminance, and high luminance areas respectively.
          * corresponding to low luminance, medium luminance, and high luminance areas respectively.
          */
          */
-        cameraColorCurves: ColorCurves;
+        cameraColorCurves: Nullable<ColorCurves>;
         private _cameraInfos;
         private _cameraInfos;
         private _microsurfaceTextureLods;
         private _microsurfaceTextureLods;
         /**
         /**
@@ -320,7 +320,7 @@ declare module BABYLON {
         private static _scaledEmissive;
         private static _scaledEmissive;
         private static _scaledReflection;
         private static _scaledReflection;
         static BindLights(scene: Scene, mesh: AbstractMesh, effect: Effect, defines: MaterialDefines, useScalarInLinearSpace: boolean, maxSimultaneousLights: number, usePhysicalLightFalloff: boolean): void;
         static BindLights(scene: Scene, mesh: AbstractMesh, effect: Effect, defines: MaterialDefines, useScalarInLinearSpace: boolean, maxSimultaneousLights: number, usePhysicalLightFalloff: boolean): void;
-        isReady(mesh?: AbstractMesh, useInstances?: boolean): boolean;
+        isReady(mesh?: Nullable<AbstractMesh>, useInstances?: boolean): boolean;
         buildUniformLayout(): void;
         buildUniformLayout(): void;
         unbind(): void;
         unbind(): void;
         bindOnlyWorldMatrix(world: Matrix): void;
         bindOnlyWorldMatrix(world: Matrix): void;

+ 43 - 31
dist/preview release/materialsLibrary/babylon.legacyPbrMaterial.js

@@ -465,6 +465,7 @@ var BABYLON;
         };
         };
         LegacyPBRMaterial.prototype.isReady = function (mesh, useInstances) {
         LegacyPBRMaterial.prototype.isReady = function (mesh, useInstances) {
             var _this = this;
             var _this = this;
+            if (mesh === void 0) { mesh = null; }
             if (this.isFrozen) {
             if (this.isFrozen) {
                 if (this._wasPreviouslyReady) {
                 if (this._wasPreviouslyReady) {
                     return true;
                     return true;
@@ -474,10 +475,10 @@ var BABYLON;
             var engine = scene.getEngine();
             var engine = scene.getEngine();
             var needUVs = false;
             var needUVs = false;
             this._defines.reset();
             this._defines.reset();
-            if (scene.lightsEnabled && !this.disableLighting) {
+            if (scene.lightsEnabled && !this.disableLighting && mesh) {
                 BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, this._defines, true, this.maxSimultaneousLights);
                 BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, this._defines, true, this.maxSimultaneousLights);
             }
             }
-            if (!this.checkReadyOnEveryCall) {
+            if (!this.checkReadyOnEveryCall && mesh) {
                 if (this._renderId === scene.getRenderId()) {
                 if (this._renderId === scene.getRenderId()) {
                     if (this._checkCache(scene, mesh, useInstances)) {
                     if (this._checkCache(scene, mesh, useInstances)) {
                         return true;
                         return true;
@@ -745,14 +746,14 @@ var BABYLON;
                 }
                 }
                 if (mesh.useBones && mesh.computeBonesUsingShaders) {
                 if (mesh.useBones && mesh.computeBonesUsingShaders) {
                     this._defines.NUM_BONE_INFLUENCERS = mesh.numBoneInfluencers;
                     this._defines.NUM_BONE_INFLUENCERS = mesh.numBoneInfluencers;
-                    this._defines.BonesPerMesh = (mesh.skeleton.bones.length + 1);
+                    this._defines.BonesPerMesh = (mesh.skeleton ? mesh.skeleton.bones.length + 1 : 0);
                 }
                 }
                 // Instances
                 // Instances
                 if (useInstances) {
                 if (useInstances) {
                     this._defines.INSTANCES = true;
                     this._defines.INSTANCES = true;
                 }
                 }
-                if (mesh.morphTargetManager) {
-                    var manager = mesh.morphTargetManager;
+                var manager = mesh.morphTargetManager;
+                if (manager) {
                     this._defines.MORPHTARGETS_TANGENT = manager.supportsTangents && this._defines.TANGENT;
                     this._defines.MORPHTARGETS_TANGENT = manager.supportsTangents && this._defines.TANGENT;
                     this._defines.MORPHTARGETS_NORMAL = manager.supportsNormals && this._defines.NORMAL;
                     this._defines.MORPHTARGETS_NORMAL = manager.supportsNormals && this._defines.NORMAL;
                     this._defines.MORPHTARGETS = (manager.numInfluencers > 0);
                     this._defines.MORPHTARGETS = (manager.numInfluencers > 0);
@@ -828,9 +829,11 @@ var BABYLON;
                 if (this._defines.VERTEXCOLOR) {
                 if (this._defines.VERTEXCOLOR) {
                     attribs.push(BABYLON.VertexBuffer.ColorKind);
                     attribs.push(BABYLON.VertexBuffer.ColorKind);
                 }
                 }
-                BABYLON.MaterialHelper.PrepareAttributesForBones(attribs, mesh, this._defines, fallbacks);
-                BABYLON.MaterialHelper.PrepareAttributesForInstances(attribs, this._defines);
-                BABYLON.MaterialHelper.PrepareAttributesForMorphTargets(attribs, mesh, this._defines);
+                if (mesh) {
+                    BABYLON.MaterialHelper.PrepareAttributesForBones(attribs, mesh, this._defines, fallbacks);
+                    BABYLON.MaterialHelper.PrepareAttributesForInstances(attribs, this._defines);
+                    BABYLON.MaterialHelper.PrepareAttributesForMorphTargets(attribs, mesh, this._defines);
+                }
                 // Legacy browser patch
                 // Legacy browser patch
                 var join = this._defines.toString();
                 var join = this._defines.toString();
                 var uniforms = ["world", "view", "viewProjection", "vEyePosition", "vLightsType", "vAmbientColor", "vAlbedoColor", "vReflectivityColor", "vEmissiveColor", "vReflectionColor",
                 var uniforms = ["world", "view", "viewProjection", "vEyePosition", "vLightsType", "vAmbientColor", "vAlbedoColor", "vReflectivityColor", "vEmissiveColor", "vReflectionColor",
@@ -882,7 +885,7 @@ var BABYLON;
                 }, engine);
                 }, engine);
                 this.buildUniformLayout();
                 this.buildUniformLayout();
             }
             }
-            if (!this._effect.isReady()) {
+            if (!this._effect || !this._effect.isReady()) {
                 return false;
                 return false;
             }
             }
             this._renderId = scene.getRenderId();
             this._renderId = scene.getRenderId();
@@ -942,15 +945,20 @@ var BABYLON;
             _super.prototype.unbind.call(this);
             _super.prototype.unbind.call(this);
         };
         };
         LegacyPBRMaterial.prototype.bindOnlyWorldMatrix = function (world) {
         LegacyPBRMaterial.prototype.bindOnlyWorldMatrix = function (world) {
-            this._effect.setMatrix("world", world);
+            if (this._effect) {
+                this._effect.setMatrix("world", world);
+            }
         };
         };
         LegacyPBRMaterial.prototype.bind = function (world, mesh) {
         LegacyPBRMaterial.prototype.bind = function (world, mesh) {
             this._myScene = this.getScene();
             this._myScene = this.getScene();
             var effect = this._effect;
             var effect = this._effect;
+            if (!effect) {
+                return;
+            }
             // Matrices        
             // Matrices        
             this.bindOnlyWorldMatrix(world);
             this.bindOnlyWorldMatrix(world);
             // Bones
             // Bones
-            BABYLON.MaterialHelper.BindBonesParameters(mesh, this._effect);
+            BABYLON.MaterialHelper.BindBonesParameters(mesh, effect);
             if (this._myScene.getCachedMaterial() !== this) {
             if (this._myScene.getCachedMaterial() !== this) {
                 this._uniformBuffer.bindToEffect(effect, "Material");
                 this._uniformBuffer.bindToEffect(effect, "Material");
                 this.bindViewProjection(effect);
                 this.bindViewProjection(effect);
@@ -985,15 +993,17 @@ var BABYLON;
                             this._uniformBuffer.updateFloat2("vReflectionInfos", this.reflectionTexture.level, 0);
                             this._uniformBuffer.updateFloat2("vReflectionInfos", this.reflectionTexture.level, 0);
                             if (this._defines.USESPHERICALFROMREFLECTIONMAP) {
                             if (this._defines.USESPHERICALFROMREFLECTIONMAP) {
                                 var polynomials = this.reflectionTexture.sphericalPolynomial;
                                 var polynomials = this.reflectionTexture.sphericalPolynomial;
-                                this._effect.setFloat3("vSphericalX", polynomials.x.x, polynomials.x.y, polynomials.x.z);
-                                this._effect.setFloat3("vSphericalY", polynomials.y.x, polynomials.y.y, polynomials.y.z);
-                                this._effect.setFloat3("vSphericalZ", polynomials.z.x, polynomials.z.y, polynomials.z.z);
-                                this._effect.setFloat3("vSphericalXX_ZZ", polynomials.xx.x - polynomials.zz.x, polynomials.xx.y - polynomials.zz.y, polynomials.xx.z - polynomials.zz.z);
-                                this._effect.setFloat3("vSphericalYY_ZZ", polynomials.yy.x - polynomials.zz.x, polynomials.yy.y - polynomials.zz.y, polynomials.yy.z - polynomials.zz.z);
-                                this._effect.setFloat3("vSphericalZZ", polynomials.zz.x, polynomials.zz.y, polynomials.zz.z);
-                                this._effect.setFloat3("vSphericalXY", polynomials.xy.x, polynomials.xy.y, polynomials.xy.z);
-                                this._effect.setFloat3("vSphericalYZ", polynomials.yz.x, polynomials.yz.y, polynomials.yz.z);
-                                this._effect.setFloat3("vSphericalZX", polynomials.zx.x, polynomials.zx.y, polynomials.zx.z);
+                                if (polynomials) {
+                                    effect.setFloat3("vSphericalX", polynomials.x.x, polynomials.x.y, polynomials.x.z);
+                                    effect.setFloat3("vSphericalY", polynomials.y.x, polynomials.y.y, polynomials.y.z);
+                                    effect.setFloat3("vSphericalZ", polynomials.z.x, polynomials.z.y, polynomials.z.z);
+                                    effect.setFloat3("vSphericalXX_ZZ", polynomials.xx.x - polynomials.zz.x, polynomials.xx.y - polynomials.zz.y, polynomials.xx.z - polynomials.zz.z);
+                                    effect.setFloat3("vSphericalYY_ZZ", polynomials.yy.x - polynomials.zz.x, polynomials.yy.y - polynomials.zz.y, polynomials.yy.z - polynomials.zz.z);
+                                    effect.setFloat3("vSphericalZZ", polynomials.zz.x, polynomials.zz.y, polynomials.zz.z);
+                                    effect.setFloat3("vSphericalXY", polynomials.xy.x, polynomials.xy.y, polynomials.xy.z);
+                                    effect.setFloat3("vSphericalYZ", polynomials.yz.x, polynomials.yz.y, polynomials.yz.z);
+                                    effect.setFloat3("vSphericalZX", polynomials.zx.x, polynomials.zx.y, polynomials.zx.z);
+                                }
                             }
                             }
                         }
                         }
                         if (this.emissiveTexture && BABYLON.StandardMaterial.EmissiveTextureEnabled) {
                         if (this.emissiveTexture && BABYLON.StandardMaterial.EmissiveTextureEnabled) {
@@ -1066,7 +1076,9 @@ var BABYLON;
                     this._uniformBuffer.updateColor3("vReflectionColor", LegacyPBRMaterial._scaledReflection);
                     this._uniformBuffer.updateColor3("vReflectionColor", LegacyPBRMaterial._scaledReflection);
                     // GAMMA CORRECTION.
                     // GAMMA CORRECTION.
                     this.convertColorToLinearSpaceToRef(this.albedoColor, LegacyPBRMaterial._scaledAlbedo);
                     this.convertColorToLinearSpaceToRef(this.albedoColor, LegacyPBRMaterial._scaledAlbedo);
-                    this._uniformBuffer.updateColor4("vAlbedoColor", LegacyPBRMaterial._scaledAlbedo, this.alpha * mesh.visibility);
+                    if (mesh) {
+                        this._uniformBuffer.updateColor4("vAlbedoColor", LegacyPBRMaterial._scaledAlbedo, this.alpha * mesh.visibility);
+                    }
                     // Misc
                     // Misc
                     this._lightingInfos.x = this.directIntensity;
                     this._lightingInfos.x = this.directIntensity;
                     this._lightingInfos.y = this.emissiveIntensity;
                     this._lightingInfos.y = this.emissiveIntensity;
@@ -1144,51 +1156,51 @@ var BABYLON;
                         }
                         }
                     }
                     }
                     if (this.cameraColorGradingTexture && BABYLON.StandardMaterial.ColorGradingTextureEnabled) {
                     if (this.cameraColorGradingTexture && BABYLON.StandardMaterial.ColorGradingTextureEnabled) {
-                        this._effect.setTexture("cameraColorGrading2DSampler", this.cameraColorGradingTexture);
+                        effect.setTexture("cameraColorGrading2DSampler", this.cameraColorGradingTexture);
                         var x = this.cameraColorGradingTexture.level; // Texture Level
                         var x = this.cameraColorGradingTexture.level; // Texture Level
                         var y = this.cameraColorGradingTexture.getSize().height; // Texture Size example with 8
                         var y = this.cameraColorGradingTexture.getSize().height; // Texture Size example with 8
                         var z = y - 1.0; // SizeMinusOne 8 - 1
                         var z = y - 1.0; // SizeMinusOne 8 - 1
                         var w = 1 / y; // Space of 1 slice 1 / 8
                         var w = 1 / y; // Space of 1 slice 1 / 8
-                        this._effect.setFloat4("vCameraColorGradingInfos", x, y, z, w);
+                        effect.setFloat4("vCameraColorGradingInfos", x, y, z, w);
                         var slicePixelSizeU = w / y; // Space of 1 pixel in U direction, e.g. 1/64
                         var slicePixelSizeU = w / y; // Space of 1 pixel in U direction, e.g. 1/64
                         var slicePixelSizeV = w; // Space of 1 pixel in V direction, e.g. 1/8					    // Space of 1 pixel in V direction, e.g. 1/8
                         var slicePixelSizeV = w; // Space of 1 pixel in V direction, e.g. 1/8					    // Space of 1 pixel in V direction, e.g. 1/8
                         var x2 = z * slicePixelSizeU; // Extent of lookup range in U for a single slice so that range corresponds to (size-1) texels, for example 7/64
                         var x2 = z * slicePixelSizeU; // Extent of lookup range in U for a single slice so that range corresponds to (size-1) texels, for example 7/64
                         var y2 = z / y; // Extent of lookup range in V for a single slice so that range corresponds to (size-1) texels, for example 7/8
                         var y2 = z / y; // Extent of lookup range in V for a single slice so that range corresponds to (size-1) texels, for example 7/8
                         var z2 = 0.5 * slicePixelSizeU; // Offset of lookup range in U to align sample position with texel centre, for example 0.5/64 
                         var z2 = 0.5 * slicePixelSizeU; // Offset of lookup range in U to align sample position with texel centre, for example 0.5/64 
                         var w2 = 0.5 * slicePixelSizeV; // Offset of lookup range in V to align sample position with texel centre, for example 0.5/8
                         var w2 = 0.5 * slicePixelSizeV; // Offset of lookup range in V to align sample position with texel centre, for example 0.5/8
-                        this._effect.setFloat4("vCameraColorGradingScaleOffset", x2, y2, z2, w2);
+                        effect.setFloat4("vCameraColorGradingScaleOffset", x2, y2, z2, w2);
                     }
                     }
                 }
                 }
                 // Clip plane
                 // Clip plane
-                BABYLON.MaterialHelper.BindClipPlane(this._effect, this._myScene);
+                BABYLON.MaterialHelper.BindClipPlane(effect, this._myScene);
                 // Colors
                 // Colors
                 this._myScene.ambientColor.multiplyToRef(this.ambientColor, this._globalAmbientColor);
                 this._myScene.ambientColor.multiplyToRef(this.ambientColor, this._globalAmbientColor);
                 effect.setVector3("vEyePosition", this._myScene._mirroredCameraPosition ? this._myScene._mirroredCameraPosition : this._myScene.activeCamera.position);
                 effect.setVector3("vEyePosition", this._myScene._mirroredCameraPosition ? this._myScene._mirroredCameraPosition : this._myScene.activeCamera.position);
                 effect.setColor3("vAmbientColor", this._globalAmbientColor);
                 effect.setColor3("vAmbientColor", this._globalAmbientColor);
             }
             }
-            if (this._myScene.getCachedMaterial() !== this || !this.isFrozen) {
+            if (mesh && (this._myScene.getCachedMaterial() !== this || !this.isFrozen)) {
                 // Lights
                 // Lights
                 if (this._myScene.lightsEnabled && !this.disableLighting) {
                 if (this._myScene.lightsEnabled && !this.disableLighting) {
-                    LegacyPBRMaterial.BindLights(this._myScene, mesh, this._effect, this._defines, this.useScalarInLinearSpace, this.maxSimultaneousLights, this.usePhysicalLightFalloff);
+                    LegacyPBRMaterial.BindLights(this._myScene, mesh, effect, this._defines, this.useScalarInLinearSpace, this.maxSimultaneousLights, this.usePhysicalLightFalloff);
                 }
                 }
                 // View
                 // View
                 if (this._myScene.fogEnabled && mesh.applyFog && this._myScene.fogMode !== BABYLON.Scene.FOGMODE_NONE || this.reflectionTexture) {
                 if (this._myScene.fogEnabled && mesh.applyFog && this._myScene.fogMode !== BABYLON.Scene.FOGMODE_NONE || this.reflectionTexture) {
                     this.bindView(effect);
                     this.bindView(effect);
                 }
                 }
                 // Fog
                 // Fog
-                BABYLON.MaterialHelper.BindFogParameters(this._myScene, mesh, this._effect);
+                BABYLON.MaterialHelper.BindFogParameters(this._myScene, mesh, effect);
                 // Morph targets
                 // Morph targets
                 if (this._defines.NUM_MORPH_INFLUENCERS) {
                 if (this._defines.NUM_MORPH_INFLUENCERS) {
-                    BABYLON.MaterialHelper.BindMorphTargetParameters(mesh, this._effect);
+                    BABYLON.MaterialHelper.BindMorphTargetParameters(mesh, effect);
                 }
                 }
                 this._cameraInfos.x = this.cameraExposure;
                 this._cameraInfos.x = this.cameraExposure;
                 this._cameraInfos.y = this.cameraContrast;
                 this._cameraInfos.y = this.cameraContrast;
                 effect.setVector4("vCameraInfos", this._cameraInfos);
                 effect.setVector4("vCameraInfos", this._cameraInfos);
                 if (this.cameraColorCurves) {
                 if (this.cameraColorCurves) {
-                    BABYLON.ColorCurves.Bind(this.cameraColorCurves, this._effect);
+                    BABYLON.ColorCurves.Bind(this.cameraColorCurves, effect);
                 }
                 }
                 // Log. depth
                 // Log. depth
-                BABYLON.MaterialHelper.BindLogDepth(this._defines, this._effect, this._myScene);
+                BABYLON.MaterialHelper.BindLogDepth(this._defines, effect, this._myScene);
             }
             }
             this._uniformBuffer.update();
             this._uniformBuffer.update();
             this._afterBind(mesh);
             this._afterBind(mesh);

File diff suppressed because it is too large
+ 2 - 2
dist/preview release/materialsLibrary/babylon.legacyPbrMaterial.min.js


+ 1 - 1
dist/preview release/materialsLibrary/babylon.normalMaterial.d.ts

@@ -12,7 +12,7 @@ declare module BABYLON {
         constructor(name: string, scene: Scene);
         constructor(name: string, scene: Scene);
         needAlphaBlending(): boolean;
         needAlphaBlending(): boolean;
         needAlphaTesting(): boolean;
         needAlphaTesting(): boolean;
-        getAlphaTestTexture(): BaseTexture;
+        getAlphaTestTexture(): Nullable<BaseTexture>;
         isReadyForSubMesh(mesh: AbstractMesh, subMesh: SubMesh, useInstances?: boolean): boolean;
         isReadyForSubMesh(mesh: AbstractMesh, subMesh: SubMesh, useInstances?: boolean): boolean;
         bindForSubMesh(world: Matrix, mesh: Mesh, subMesh: SubMesh): void;
         bindForSubMesh(world: Matrix, mesh: Mesh, subMesh: SubMesh): void;
         getAnimatables(): IAnimatable[];
         getAnimatables(): IAnimatable[];

+ 5 - 2
dist/preview release/materialsLibrary/babylon.normalMaterial.js

@@ -129,7 +129,7 @@ var BABYLON;
             // Lights
             // Lights
             defines._needNormals = BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights, this._disableLighting);
             defines._needNormals = BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights, this._disableLighting);
             // Values that need to be evaluated on every frame
             // Values that need to be evaluated on every frame
-            BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances);
+            BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false);
             // Attribs
             // Attribs
             BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true);
             BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true);
             // Get correct effect      
             // Get correct effect      
@@ -190,7 +190,7 @@ var BABYLON;
                     indexParameters: { maxSimultaneousLights: 4 }
                     indexParameters: { maxSimultaneousLights: 4 }
                 }, engine), defines);
                 }, engine), defines);
             }
             }
-            if (!subMesh.effect.isReady()) {
+            if (!subMesh.effect || !subMesh.effect.isReady()) {
                 return false;
                 return false;
             }
             }
             this._renderId = scene.getRenderId();
             this._renderId = scene.getRenderId();
@@ -204,6 +204,9 @@ var BABYLON;
                 return;
                 return;
             }
             }
             var effect = subMesh.effect;
             var effect = subMesh.effect;
+            if (!effect) {
+                return;
+            }
             this._activeEffect = effect;
             this._activeEffect = effect;
             // Matrices        
             // Matrices        
             this.bindOnlyWorldMatrix(world);
             this.bindOnlyWorldMatrix(world);

File diff suppressed because it is too large
+ 1 - 1
dist/preview release/materialsLibrary/babylon.normalMaterial.min.js


+ 1 - 1
dist/preview release/materialsLibrary/babylon.shadowOnlyMaterial.d.ts

@@ -6,7 +6,7 @@ declare module BABYLON {
         constructor(name: string, scene: Scene);
         constructor(name: string, scene: Scene);
         needAlphaBlending(): boolean;
         needAlphaBlending(): boolean;
         needAlphaTesting(): boolean;
         needAlphaTesting(): boolean;
-        getAlphaTestTexture(): BaseTexture;
+        getAlphaTestTexture(): Nullable<BaseTexture>;
         activeLight: IShadowLight;
         activeLight: IShadowLight;
         isReadyForSubMesh(mesh: AbstractMesh, subMesh: SubMesh, useInstances?: boolean): boolean;
         isReadyForSubMesh(mesh: AbstractMesh, subMesh: SubMesh, useInstances?: boolean): boolean;
         bindForSubMesh(world: Matrix, mesh: Mesh, subMesh: SubMesh): void;
         bindForSubMesh(world: Matrix, mesh: Mesh, subMesh: SubMesh): void;

+ 5 - 2
dist/preview release/materialsLibrary/babylon.shadowOnlyMaterial.js

@@ -86,7 +86,7 @@ var BABYLON;
                     }
                     }
                 }
                 }
             }
             }
-            BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances);
+            BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false);
             BABYLON.MaterialHelper.PrepareDefinesForMisc(mesh, scene, false, this.pointsCloud, this.fogEnabled, defines);
             BABYLON.MaterialHelper.PrepareDefinesForMisc(mesh, scene, false, this.pointsCloud, this.fogEnabled, defines);
             defines._needNormals = BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, 1);
             defines._needNormals = BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, 1);
             // Attribs
             // Attribs
@@ -139,7 +139,7 @@ var BABYLON;
                     indexParameters: { maxSimultaneousLights: 1 }
                     indexParameters: { maxSimultaneousLights: 1 }
                 }, engine), defines);
                 }, engine), defines);
             }
             }
-            if (!subMesh.effect.isReady()) {
+            if (!subMesh.effect || !subMesh.effect.isReady()) {
                 return false;
                 return false;
             }
             }
             this._renderId = scene.getRenderId();
             this._renderId = scene.getRenderId();
@@ -153,6 +153,9 @@ var BABYLON;
                 return;
                 return;
             }
             }
             var effect = subMesh.effect;
             var effect = subMesh.effect;
+            if (!effect) {
+                return;
+            }
             this._activeEffect = effect;
             this._activeEffect = effect;
             // Matrices        
             // Matrices        
             this.bindOnlyWorldMatrix(world);
             this.bindOnlyWorldMatrix(world);

File diff suppressed because it is too large
+ 1 - 1
dist/preview release/materialsLibrary/babylon.shadowOnlyMaterial.min.js


+ 1 - 1
dist/preview release/materialsLibrary/babylon.simpleMaterial.d.ts

@@ -12,7 +12,7 @@ declare module BABYLON {
         constructor(name: string, scene: Scene);
         constructor(name: string, scene: Scene);
         needAlphaBlending(): boolean;
         needAlphaBlending(): boolean;
         needAlphaTesting(): boolean;
         needAlphaTesting(): boolean;
-        getAlphaTestTexture(): BaseTexture;
+        getAlphaTestTexture(): Nullable<BaseTexture>;
         isReadyForSubMesh(mesh: AbstractMesh, subMesh: SubMesh, useInstances?: boolean): boolean;
         isReadyForSubMesh(mesh: AbstractMesh, subMesh: SubMesh, useInstances?: boolean): boolean;
         bindForSubMesh(world: Matrix, mesh: Mesh, subMesh: SubMesh): void;
         bindForSubMesh(world: Matrix, mesh: Mesh, subMesh: SubMesh): void;
         getAnimatables(): IAnimatable[];
         getAnimatables(): IAnimatable[];

+ 5 - 2
dist/preview release/materialsLibrary/babylon.simpleMaterial.js

@@ -96,7 +96,7 @@ var BABYLON;
             // Lights
             // Lights
             defines._needNormals = BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights, this._disableLighting);
             defines._needNormals = BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights, this._disableLighting);
             // Values that need to be evaluated on every frame
             // Values that need to be evaluated on every frame
-            BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances);
+            BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false);
             // Attribs
             // Attribs
             BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true);
             BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true);
             // Get correct effect      
             // Get correct effect      
@@ -157,7 +157,7 @@ var BABYLON;
                     indexParameters: { maxSimultaneousLights: this._maxSimultaneousLights - 1 }
                     indexParameters: { maxSimultaneousLights: this._maxSimultaneousLights - 1 }
                 }, engine), defines);
                 }, engine), defines);
             }
             }
-            if (!subMesh.effect.isReady()) {
+            if (!subMesh.effect || !subMesh.effect.isReady()) {
                 return false;
                 return false;
             }
             }
             this._renderId = scene.getRenderId();
             this._renderId = scene.getRenderId();
@@ -171,6 +171,9 @@ var BABYLON;
                 return;
                 return;
             }
             }
             var effect = subMesh.effect;
             var effect = subMesh.effect;
+            if (!effect) {
+                return;
+            }
             this._activeEffect = effect;
             this._activeEffect = effect;
             // Matrices        
             // Matrices        
             this.bindOnlyWorldMatrix(world);
             this.bindOnlyWorldMatrix(world);

File diff suppressed because it is too large
+ 1 - 1
dist/preview release/materialsLibrary/babylon.simpleMaterial.min.js


+ 1 - 1
dist/preview release/materialsLibrary/babylon.skyMaterial.d.ts

@@ -16,7 +16,7 @@ declare module BABYLON {
         constructor(name: string, scene: Scene);
         constructor(name: string, scene: Scene);
         needAlphaBlending(): boolean;
         needAlphaBlending(): boolean;
         needAlphaTesting(): boolean;
         needAlphaTesting(): boolean;
-        getAlphaTestTexture(): BaseTexture;
+        getAlphaTestTexture(): Nullable<BaseTexture>;
         isReadyForSubMesh(mesh: AbstractMesh, subMesh: SubMesh, useInstances?: boolean): boolean;
         isReadyForSubMesh(mesh: AbstractMesh, subMesh: SubMesh, useInstances?: boolean): boolean;
         bindForSubMesh(world: Matrix, mesh: Mesh, subMesh: SubMesh): void;
         bindForSubMesh(world: Matrix, mesh: Mesh, subMesh: SubMesh): void;
         getAnimatables(): IAnimatable[];
         getAnimatables(): IAnimatable[];

+ 4 - 1
dist/preview release/materialsLibrary/babylon.skyMaterial.js

@@ -101,7 +101,7 @@ var BABYLON;
                     "cameraPosition"
                     "cameraPosition"
                 ], [], join, fallbacks, this.onCompiled, this.onError), defines);
                 ], [], join, fallbacks, this.onCompiled, this.onError), defines);
             }
             }
-            if (!subMesh.effect.isReady()) {
+            if (!subMesh.effect || !subMesh.effect.isReady()) {
                 return false;
                 return false;
             }
             }
             this._renderId = scene.getRenderId();
             this._renderId = scene.getRenderId();
@@ -115,6 +115,9 @@ var BABYLON;
                 return;
                 return;
             }
             }
             var effect = subMesh.effect;
             var effect = subMesh.effect;
+            if (!effect) {
+                return;
+            }
             this._activeEffect = effect;
             this._activeEffect = effect;
             // Matrices        
             // Matrices        
             this.bindOnlyWorldMatrix(world);
             this.bindOnlyWorldMatrix(world);

File diff suppressed because it is too large
+ 1 - 1
dist/preview release/materialsLibrary/babylon.skyMaterial.min.js


+ 1 - 1
dist/preview release/materialsLibrary/babylon.terrainMaterial.d.ts

@@ -26,7 +26,7 @@ declare module BABYLON {
         constructor(name: string, scene: Scene);
         constructor(name: string, scene: Scene);
         needAlphaBlending(): boolean;
         needAlphaBlending(): boolean;
         needAlphaTesting(): boolean;
         needAlphaTesting(): boolean;
-        getAlphaTestTexture(): BaseTexture;
+        getAlphaTestTexture(): Nullable<BaseTexture>;
         isReadyForSubMesh(mesh: AbstractMesh, subMesh: SubMesh, useInstances?: boolean): boolean;
         isReadyForSubMesh(mesh: AbstractMesh, subMesh: SubMesh, useInstances?: boolean): boolean;
         bindForSubMesh(world: Matrix, mesh: Mesh, subMesh: SubMesh): void;
         bindForSubMesh(world: Matrix, mesh: Mesh, subMesh: SubMesh): void;
         getAnimatables(): IAnimatable[];
         getAnimatables(): IAnimatable[];

+ 5 - 2
dist/preview release/materialsLibrary/babylon.terrainMaterial.js

@@ -102,7 +102,7 @@ var BABYLON;
             // Lights
             // Lights
             defines._needNormals = BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights, this._disableLighting);
             defines._needNormals = BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights, this._disableLighting);
             // Values that need to be evaluated on every frame
             // Values that need to be evaluated on every frame
-            BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances);
+            BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false);
             // Attribs
             // Attribs
             BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true);
             BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true);
             // Get correct effect      
             // Get correct effect      
@@ -167,7 +167,7 @@ var BABYLON;
                     indexParameters: { maxSimultaneousLights: this.maxSimultaneousLights }
                     indexParameters: { maxSimultaneousLights: this.maxSimultaneousLights }
                 }, engine), defines);
                 }, engine), defines);
             }
             }
-            if (!subMesh.effect.isReady()) {
+            if (!subMesh.effect || !subMesh.effect.isReady()) {
                 return false;
                 return false;
             }
             }
             this._renderId = scene.getRenderId();
             this._renderId = scene.getRenderId();
@@ -181,6 +181,9 @@ var BABYLON;
                 return;
                 return;
             }
             }
             var effect = subMesh.effect;
             var effect = subMesh.effect;
+            if (!effect) {
+                return;
+            }
             this._activeEffect = effect;
             this._activeEffect = effect;
             // Matrices        
             // Matrices        
             this.bindOnlyWorldMatrix(world);
             this.bindOnlyWorldMatrix(world);

File diff suppressed because it is too large
+ 1 - 1
dist/preview release/materialsLibrary/babylon.terrainMaterial.min.js


+ 1 - 1
dist/preview release/materialsLibrary/babylon.triPlanarMaterial.d.ts

@@ -26,7 +26,7 @@ declare module BABYLON {
         constructor(name: string, scene: Scene);
         constructor(name: string, scene: Scene);
         needAlphaBlending(): boolean;
         needAlphaBlending(): boolean;
         needAlphaTesting(): boolean;
         needAlphaTesting(): boolean;
-        getAlphaTestTexture(): BaseTexture;
+        getAlphaTestTexture(): Nullable<BaseTexture>;
         isReadyForSubMesh(mesh: AbstractMesh, subMesh: SubMesh, useInstances?: boolean): boolean;
         isReadyForSubMesh(mesh: AbstractMesh, subMesh: SubMesh, useInstances?: boolean): boolean;
         bindForSubMesh(world: Matrix, mesh: Mesh, subMesh: SubMesh): void;
         bindForSubMesh(world: Matrix, mesh: Mesh, subMesh: SubMesh): void;
         getAnimatables(): IAnimatable[];
         getAnimatables(): IAnimatable[];

+ 5 - 2
dist/preview release/materialsLibrary/babylon.triPlanarMaterial.js

@@ -121,7 +121,7 @@ var BABYLON;
             // Lights
             // Lights
             defines._needNormals = BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights, this._disableLighting);
             defines._needNormals = BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights, this._disableLighting);
             // Values that need to be evaluated on every frame
             // Values that need to be evaluated on every frame
-            BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances);
+            BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false);
             // Attribs
             // Attribs
             BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true);
             BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true);
             // Get correct effect      
             // Get correct effect      
@@ -179,7 +179,7 @@ var BABYLON;
                     indexParameters: { maxSimultaneousLights: this.maxSimultaneousLights }
                     indexParameters: { maxSimultaneousLights: this.maxSimultaneousLights }
                 }, engine), defines);
                 }, engine), defines);
             }
             }
-            if (!subMesh.effect.isReady()) {
+            if (!subMesh.effect || !subMesh.effect.isReady()) {
                 return false;
                 return false;
             }
             }
             this._renderId = scene.getRenderId();
             this._renderId = scene.getRenderId();
@@ -193,6 +193,9 @@ var BABYLON;
                 return;
                 return;
             }
             }
             var effect = subMesh.effect;
             var effect = subMesh.effect;
+            if (!effect) {
+                return;
+            }
             this._activeEffect = effect;
             this._activeEffect = effect;
             // Matrices        
             // Matrices        
             this.bindOnlyWorldMatrix(world);
             this.bindOnlyWorldMatrix(world);

File diff suppressed because it is too large
+ 1 - 1
dist/preview release/materialsLibrary/babylon.triPlanarMaterial.min.js


+ 2 - 2
dist/preview release/materialsLibrary/babylon.waterMaterial.d.ts

@@ -84,11 +84,11 @@ declare module BABYLON {
         readonly reflectionTexture: RenderTargetTexture;
         readonly reflectionTexture: RenderTargetTexture;
         addToRenderList(node: any): void;
         addToRenderList(node: any): void;
         enableRenderTargets(enable: boolean): void;
         enableRenderTargets(enable: boolean): void;
-        getRenderList(): AbstractMesh[];
+        getRenderList(): Nullable<AbstractMesh[]>;
         readonly renderTargetsEnabled: boolean;
         readonly renderTargetsEnabled: boolean;
         needAlphaBlending(): boolean;
         needAlphaBlending(): boolean;
         needAlphaTesting(): boolean;
         needAlphaTesting(): boolean;
-        getAlphaTestTexture(): BaseTexture;
+        getAlphaTestTexture(): Nullable<BaseTexture>;
         isReadyForSubMesh(mesh: AbstractMesh, subMesh: SubMesh, useInstances?: boolean): boolean;
         isReadyForSubMesh(mesh: AbstractMesh, subMesh: SubMesh, useInstances?: boolean): boolean;
         bindForSubMesh(world: Matrix, mesh: Mesh, subMesh: SubMesh): void;
         bindForSubMesh(world: Matrix, mesh: Mesh, subMesh: SubMesh): void;
         private _createRenderTargets(scene, renderTargetSize);
         private _createRenderTargets(scene, renderTargetSize);

+ 11 - 4
dist/preview release/materialsLibrary/babylon.waterMaterial.js

@@ -158,8 +158,12 @@ var BABYLON;
         });
         });
         // Methods
         // Methods
         WaterMaterial.prototype.addToRenderList = function (node) {
         WaterMaterial.prototype.addToRenderList = function (node) {
-            this._refractionRTT.renderList.push(node);
-            this._reflectionRTT.renderList.push(node);
+            if (this._refractionRTT.renderList) {
+                this._refractionRTT.renderList.push(node);
+            }
+            if (this._reflectionRTT.renderList) {
+                this._reflectionRTT.renderList.push(node);
+            }
         };
         };
         WaterMaterial.prototype.enableRenderTargets = function (enable) {
         WaterMaterial.prototype.enableRenderTargets = function (enable) {
             var refreshRate = enable ? 1 : 0;
             var refreshRate = enable ? 1 : 0;
@@ -220,7 +224,7 @@ var BABYLON;
                     }
                     }
                 }
                 }
             }
             }
-            BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances);
+            BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false);
             BABYLON.MaterialHelper.PrepareDefinesForMisc(mesh, scene, this._useLogarithmicDepth, this.pointsCloud, this.fogEnabled, defines);
             BABYLON.MaterialHelper.PrepareDefinesForMisc(mesh, scene, this._useLogarithmicDepth, this.pointsCloud, this.fogEnabled, defines);
             if (defines._areMiscDirty) {
             if (defines._areMiscDirty) {
                 if (this._fresnelSeparate) {
                 if (this._fresnelSeparate) {
@@ -307,7 +311,7 @@ var BABYLON;
                     indexParameters: { maxSimultaneousLights: this._maxSimultaneousLights }
                     indexParameters: { maxSimultaneousLights: this._maxSimultaneousLights }
                 }, engine), defines);
                 }, engine), defines);
             }
             }
-            if (!subMesh.effect.isReady()) {
+            if (!subMesh.effect || !subMesh.effect.isReady()) {
                 return false;
                 return false;
             }
             }
             this._renderId = scene.getRenderId();
             this._renderId = scene.getRenderId();
@@ -321,6 +325,9 @@ var BABYLON;
                 return;
                 return;
             }
             }
             var effect = subMesh.effect;
             var effect = subMesh.effect;
+            if (!effect || !this._mesh) {
+                return;
+            }
             this._activeEffect = effect;
             this._activeEffect = effect;
             // Matrices        
             // Matrices        
             this.bindOnlyWorldMatrix(world);
             this.bindOnlyWorldMatrix(world);

File diff suppressed because it is too large
+ 1 - 1
dist/preview release/materialsLibrary/babylon.waterMaterial.min.js


+ 138 - 70
dist/preview release/materialsLibrary/babylonjs.materials.js

@@ -95,7 +95,7 @@ var BABYLON;
                     }
                     }
                 }
                 }
             }
             }
-            BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances);
+            BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false);
             BABYLON.MaterialHelper.PrepareDefinesForMisc(mesh, scene, false, this.pointsCloud, this.fogEnabled, defines);
             BABYLON.MaterialHelper.PrepareDefinesForMisc(mesh, scene, false, this.pointsCloud, this.fogEnabled, defines);
             defines._needNormals = BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, 1);
             defines._needNormals = BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, 1);
             // Attribs
             // Attribs
@@ -148,7 +148,7 @@ var BABYLON;
                     indexParameters: { maxSimultaneousLights: 1 }
                     indexParameters: { maxSimultaneousLights: 1 }
                 }, engine), defines);
                 }, engine), defines);
             }
             }
-            if (!subMesh.effect.isReady()) {
+            if (!subMesh.effect || !subMesh.effect.isReady()) {
                 return false;
                 return false;
             }
             }
             this._renderId = scene.getRenderId();
             this._renderId = scene.getRenderId();
@@ -162,6 +162,9 @@ var BABYLON;
                 return;
                 return;
             }
             }
             var effect = subMesh.effect;
             var effect = subMesh.effect;
+            if (!effect) {
+                return;
+            }
             this._activeEffect = effect;
             this._activeEffect = effect;
             // Matrices        
             // Matrices        
             this.bindOnlyWorldMatrix(world);
             this.bindOnlyWorldMatrix(world);
@@ -322,7 +325,7 @@ var BABYLON;
                 }
                 }
             }
             }
             var engine = scene.getEngine();
             var engine = scene.getEngine();
-            BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances);
+            BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false);
             BABYLON.MaterialHelper.PrepareDefinesForMisc(mesh, scene, false, this.pointsCloud, this.fogEnabled, defines);
             BABYLON.MaterialHelper.PrepareDefinesForMisc(mesh, scene, false, this.pointsCloud, this.fogEnabled, defines);
             defines._needNormals = BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights);
             defines._needNormals = BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights);
             // Attribs
             // Attribs
@@ -387,7 +390,7 @@ var BABYLON;
                     indexParameters: { maxSimultaneousLights: 4 }
                     indexParameters: { maxSimultaneousLights: 4 }
                 }, engine), defines);
                 }, engine), defines);
             }
             }
-            if (!subMesh.effect.isReady()) {
+            if (!subMesh.effect || !subMesh.effect.isReady()) {
                 return false;
                 return false;
             }
             }
             this._renderId = scene.getRenderId();
             this._renderId = scene.getRenderId();
@@ -401,15 +404,18 @@ var BABYLON;
                 return;
                 return;
             }
             }
             var effect = subMesh.effect;
             var effect = subMesh.effect;
+            if (!effect) {
+                return;
+            }
             this._activeEffect = effect;
             this._activeEffect = effect;
             // Matrices        
             // Matrices        
             this.bindOnlyWorldMatrix(world);
             this.bindOnlyWorldMatrix(world);
             this._activeEffect.setMatrix("viewProjection", scene.getTransformMatrix());
             this._activeEffect.setMatrix("viewProjection", scene.getTransformMatrix());
             // Bones
             // Bones
-            BABYLON.MaterialHelper.BindBonesParameters(mesh, this._effect);
+            BABYLON.MaterialHelper.BindBonesParameters(mesh, effect);
             if (this._mustRebind(scene, effect)) {
             if (this._mustRebind(scene, effect)) {
                 // Clip plane
                 // Clip plane
-                BABYLON.MaterialHelper.BindClipPlane(this._effect, scene);
+                BABYLON.MaterialHelper.BindClipPlane(effect, scene);
                 // Point size
                 // Point size
                 if (this.pointsCloud) {
                 if (this.pointsCloud) {
                     this._activeEffect.setFloat("pointSize", this.pointSize);
                     this._activeEffect.setFloat("pointSize", this.pointSize);
@@ -608,7 +614,7 @@ var BABYLON;
             // Lights
             // Lights
             defines._needNormals = BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights, this._disableLighting);
             defines._needNormals = BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights, this._disableLighting);
             // Values that need to be evaluated on every frame
             // Values that need to be evaluated on every frame
-            BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances);
+            BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false);
             // Attribs
             // Attribs
             BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true);
             BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true);
             // Get correct effect      
             // Get correct effect      
@@ -669,7 +675,7 @@ var BABYLON;
                     indexParameters: { maxSimultaneousLights: 4 }
                     indexParameters: { maxSimultaneousLights: 4 }
                 }, engine), defines);
                 }, engine), defines);
             }
             }
-            if (!subMesh.effect.isReady()) {
+            if (!subMesh.effect || !subMesh.effect.isReady()) {
                 return false;
                 return false;
             }
             }
             this._renderId = scene.getRenderId();
             this._renderId = scene.getRenderId();
@@ -683,6 +689,9 @@ var BABYLON;
                 return;
                 return;
             }
             }
             var effect = subMesh.effect;
             var effect = subMesh.effect;
+            if (!effect) {
+                return;
+            }
             this._activeEffect = effect;
             this._activeEffect = effect;
             // Matrices        
             // Matrices        
             this.bindOnlyWorldMatrix(world);
             this.bindOnlyWorldMatrix(world);
@@ -916,7 +925,7 @@ var BABYLON;
             // Lights
             // Lights
             defines._needNormals = BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights, this._disableLighting);
             defines._needNormals = BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights, this._disableLighting);
             // Values that need to be evaluated on every frame
             // Values that need to be evaluated on every frame
-            BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances);
+            BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false);
             // Attribs
             // Attribs
             BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true);
             BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true);
             // Get correct effect      
             // Get correct effect      
@@ -982,7 +991,7 @@ var BABYLON;
                     indexParameters: { maxSimultaneousLights: this.maxSimultaneousLights }
                     indexParameters: { maxSimultaneousLights: this.maxSimultaneousLights }
                 }, engine), defines);
                 }, engine), defines);
             }
             }
-            if (!subMesh.effect.isReady()) {
+            if (!subMesh.effect || !subMesh.effect.isReady()) {
                 return false;
                 return false;
             }
             }
             this._renderId = scene.getRenderId();
             this._renderId = scene.getRenderId();
@@ -996,6 +1005,9 @@ var BABYLON;
                 return;
                 return;
             }
             }
             var effect = subMesh.effect;
             var effect = subMesh.effect;
+            if (!effect) {
+                return;
+            }
             this._activeEffect = effect;
             this._activeEffect = effect;
             // Matrices        
             // Matrices        
             this.bindOnlyWorldMatrix(world);
             this.bindOnlyWorldMatrix(world);
@@ -1225,7 +1237,7 @@ var BABYLON;
             // Lights
             // Lights
             defines._needNormals = BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights, this._disableLighting);
             defines._needNormals = BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights, this._disableLighting);
             // Values that need to be evaluated on every frame
             // Values that need to be evaluated on every frame
-            BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances);
+            BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false);
             // Attribs
             // Attribs
             BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true);
             BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true);
             // Get correct effect      
             // Get correct effect      
@@ -1286,7 +1298,7 @@ var BABYLON;
                     indexParameters: { maxSimultaneousLights: this._maxSimultaneousLights - 1 }
                     indexParameters: { maxSimultaneousLights: this._maxSimultaneousLights - 1 }
                 }, engine), defines);
                 }, engine), defines);
             }
             }
-            if (!subMesh.effect.isReady()) {
+            if (!subMesh.effect || !subMesh.effect.isReady()) {
                 return false;
                 return false;
             }
             }
             this._renderId = scene.getRenderId();
             this._renderId = scene.getRenderId();
@@ -1300,6 +1312,9 @@ var BABYLON;
                 return;
                 return;
             }
             }
             var effect = subMesh.effect;
             var effect = subMesh.effect;
+            if (!effect) {
+                return;
+            }
             this._activeEffect = effect;
             this._activeEffect = effect;
             // Matrices        
             // Matrices        
             this.bindOnlyWorldMatrix(world);
             this.bindOnlyWorldMatrix(world);
@@ -1556,8 +1571,12 @@ var BABYLON;
         });
         });
         // Methods
         // Methods
         WaterMaterial.prototype.addToRenderList = function (node) {
         WaterMaterial.prototype.addToRenderList = function (node) {
-            this._refractionRTT.renderList.push(node);
-            this._reflectionRTT.renderList.push(node);
+            if (this._refractionRTT.renderList) {
+                this._refractionRTT.renderList.push(node);
+            }
+            if (this._reflectionRTT.renderList) {
+                this._reflectionRTT.renderList.push(node);
+            }
         };
         };
         WaterMaterial.prototype.enableRenderTargets = function (enable) {
         WaterMaterial.prototype.enableRenderTargets = function (enable) {
             var refreshRate = enable ? 1 : 0;
             var refreshRate = enable ? 1 : 0;
@@ -1618,7 +1637,7 @@ var BABYLON;
                     }
                     }
                 }
                 }
             }
             }
-            BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances);
+            BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false);
             BABYLON.MaterialHelper.PrepareDefinesForMisc(mesh, scene, this._useLogarithmicDepth, this.pointsCloud, this.fogEnabled, defines);
             BABYLON.MaterialHelper.PrepareDefinesForMisc(mesh, scene, this._useLogarithmicDepth, this.pointsCloud, this.fogEnabled, defines);
             if (defines._areMiscDirty) {
             if (defines._areMiscDirty) {
                 if (this._fresnelSeparate) {
                 if (this._fresnelSeparate) {
@@ -1705,7 +1724,7 @@ var BABYLON;
                     indexParameters: { maxSimultaneousLights: this._maxSimultaneousLights }
                     indexParameters: { maxSimultaneousLights: this._maxSimultaneousLights }
                 }, engine), defines);
                 }, engine), defines);
             }
             }
-            if (!subMesh.effect.isReady()) {
+            if (!subMesh.effect || !subMesh.effect.isReady()) {
                 return false;
                 return false;
             }
             }
             this._renderId = scene.getRenderId();
             this._renderId = scene.getRenderId();
@@ -1719,6 +1738,9 @@ var BABYLON;
                 return;
                 return;
             }
             }
             var effect = subMesh.effect;
             var effect = subMesh.effect;
+            if (!effect || !this._mesh) {
+                return;
+            }
             this._activeEffect = effect;
             this._activeEffect = effect;
             // Matrices        
             // Matrices        
             this.bindOnlyWorldMatrix(world);
             this.bindOnlyWorldMatrix(world);
@@ -2084,7 +2106,7 @@ var BABYLON;
                 defines.FOG = (scene.fogEnabled && mesh.applyFog && scene.fogMode !== BABYLON.Scene.FOGMODE_NONE && this.fogEnabled);
                 defines.FOG = (scene.fogEnabled && mesh.applyFog && scene.fogMode !== BABYLON.Scene.FOGMODE_NONE && this.fogEnabled);
             }
             }
             // Values that need to be evaluated on every frame
             // Values that need to be evaluated on every frame
-            BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances);
+            BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false);
             // Attribs
             // Attribs
             BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, false, true);
             BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, false, true);
             // Get correct effect      
             // Get correct effect      
@@ -2130,10 +2152,12 @@ var BABYLON;
                     defines: join,
                     defines: join,
                     fallbacks: fallbacks,
                     fallbacks: fallbacks,
                     onCompiled: this.onCompiled,
                     onCompiled: this.onCompiled,
-                    onError: this.onError
+                    onError: this.onError,
+                    indexParameters: null,
+                    maxSimultaneousLights: 4
                 }, engine), defines);
                 }, engine), defines);
             }
             }
-            if (!subMesh.effect.isReady()) {
+            if (!subMesh.effect || !subMesh.effect.isReady()) {
                 return false;
                 return false;
             }
             }
             this._renderId = scene.getRenderId();
             this._renderId = scene.getRenderId();
@@ -2147,6 +2171,9 @@ var BABYLON;
                 return;
                 return;
             }
             }
             var effect = subMesh.effect;
             var effect = subMesh.effect;
+            if (!effect) {
+                return;
+            }
             this._activeEffect = effect;
             this._activeEffect = effect;
             // Matrices
             // Matrices
             this.bindOnlyWorldMatrix(world);
             this.bindOnlyWorldMatrix(world);
@@ -2452,7 +2479,7 @@ var BABYLON;
             // Lights
             // Lights
             defines._needNormals = BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights, this._disableLighting);
             defines._needNormals = BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights, this._disableLighting);
             // Values that need to be evaluated on every frame
             // Values that need to be evaluated on every frame
-            BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances);
+            BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false);
             // Attribs
             // Attribs
             BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true);
             BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true);
             // Get correct effect      
             // Get correct effect      
@@ -2517,7 +2544,7 @@ var BABYLON;
                     indexParameters: { maxSimultaneousLights: this.maxSimultaneousLights }
                     indexParameters: { maxSimultaneousLights: this.maxSimultaneousLights }
                 }, engine), defines);
                 }, engine), defines);
             }
             }
-            if (!subMesh.effect.isReady()) {
+            if (!subMesh.effect || !subMesh.effect.isReady()) {
                 return false;
                 return false;
             }
             }
             this._renderId = scene.getRenderId();
             this._renderId = scene.getRenderId();
@@ -2531,6 +2558,9 @@ var BABYLON;
                 return;
                 return;
             }
             }
             var effect = subMesh.effect;
             var effect = subMesh.effect;
+            if (!effect) {
+                return;
+            }
             this._activeEffect = effect;
             this._activeEffect = effect;
             // Matrices        
             // Matrices        
             this.bindOnlyWorldMatrix(world);
             this.bindOnlyWorldMatrix(world);
@@ -2617,7 +2647,10 @@ var BABYLON;
             }
             }
             if (this._meshes) {
             if (this._meshes) {
                 for (var i = 1; i < this._meshes.length; i++) {
                 for (var i = 1; i < this._meshes.length; i++) {
-                    this._meshes[i].material.dispose(forceDisposeEffect);
+                    var mat = this._meshes[i].material;
+                    if (mat) {
+                        mat.dispose(forceDisposeEffect);
+                    }
                     this._meshes[i].dispose();
                     this._meshes[i].dispose();
                 }
                 }
             }
             }
@@ -2863,7 +2896,7 @@ var BABYLON;
             // Lights
             // Lights
             defines._needNormals = BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights, this._disableLighting);
             defines._needNormals = BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights, this._disableLighting);
             // Values that need to be evaluated on every frame
             // Values that need to be evaluated on every frame
-            BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances);
+            BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false);
             // Attribs
             // Attribs
             BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true);
             BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true);
             // Get correct effect      
             // Get correct effect      
@@ -2928,7 +2961,7 @@ var BABYLON;
                     indexParameters: { maxSimultaneousLights: this.maxSimultaneousLights }
                     indexParameters: { maxSimultaneousLights: this.maxSimultaneousLights }
                 }, engine), defines);
                 }, engine), defines);
             }
             }
-            if (!subMesh.effect.isReady()) {
+            if (!subMesh.effect || !subMesh.effect.isReady()) {
                 return false;
                 return false;
             }
             }
             this._renderId = scene.getRenderId();
             this._renderId = scene.getRenderId();
@@ -2942,6 +2975,9 @@ var BABYLON;
                 return;
                 return;
             }
             }
             var effect = subMesh.effect;
             var effect = subMesh.effect;
+            if (!effect) {
+                return;
+            }
             this._activeEffect = effect;
             this._activeEffect = effect;
             // Matrices        
             // Matrices        
             this.bindOnlyWorldMatrix(world);
             this.bindOnlyWorldMatrix(world);
@@ -3266,7 +3302,7 @@ var BABYLON;
             // Lights
             // Lights
             defines._needNormals = BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights, this._disableLighting);
             defines._needNormals = BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights, this._disableLighting);
             // Values that need to be evaluated on every frame
             // Values that need to be evaluated on every frame
-            BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances);
+            BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false);
             // Attribs
             // Attribs
             BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true);
             BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true);
             // Get correct effect      
             // Get correct effect      
@@ -3324,7 +3360,7 @@ var BABYLON;
                     indexParameters: { maxSimultaneousLights: this.maxSimultaneousLights }
                     indexParameters: { maxSimultaneousLights: this.maxSimultaneousLights }
                 }, engine), defines);
                 }, engine), defines);
             }
             }
-            if (!subMesh.effect.isReady()) {
+            if (!subMesh.effect || !subMesh.effect.isReady()) {
                 return false;
                 return false;
             }
             }
             this._renderId = scene.getRenderId();
             this._renderId = scene.getRenderId();
@@ -3338,6 +3374,9 @@ var BABYLON;
                 return;
                 return;
             }
             }
             var effect = subMesh.effect;
             var effect = subMesh.effect;
+            if (!effect) {
+                return;
+            }
             this._activeEffect = effect;
             this._activeEffect = effect;
             // Matrices        
             // Matrices        
             this.bindOnlyWorldMatrix(world);
             this.bindOnlyWorldMatrix(world);
@@ -3625,7 +3664,7 @@ var BABYLON;
                     "cameraPosition"
                     "cameraPosition"
                 ], [], join, fallbacks, this.onCompiled, this.onError), defines);
                 ], [], join, fallbacks, this.onCompiled, this.onError), defines);
             }
             }
-            if (!subMesh.effect.isReady()) {
+            if (!subMesh.effect || !subMesh.effect.isReady()) {
                 return false;
                 return false;
             }
             }
             this._renderId = scene.getRenderId();
             this._renderId = scene.getRenderId();
@@ -3639,6 +3678,9 @@ var BABYLON;
                 return;
                 return;
             }
             }
             var effect = subMesh.effect;
             var effect = subMesh.effect;
+            if (!effect) {
+                return;
+            }
             this._activeEffect = effect;
             this._activeEffect = effect;
             // Matrices        
             // Matrices        
             this.bindOnlyWorldMatrix(world);
             this.bindOnlyWorldMatrix(world);
@@ -3852,9 +3894,9 @@ var BABYLON;
                 var attribs = [BABYLON.VertexBuffer.PositionKind, BABYLON.VertexBuffer.NormalKind];
                 var attribs = [BABYLON.VertexBuffer.PositionKind, BABYLON.VertexBuffer.NormalKind];
                 // Defines
                 // Defines
                 var join = defines.toString();
                 var join = defines.toString();
-                subMesh.setEffect(scene.getEngine().createEffect("grid", attribs, ["projection", "worldView", "mainColor", "lineColor", "gridControl", "gridOffset", "vFogInfos", "vFogColor", "world", "view"], [], join, null, this.onCompiled, this.onError), defines);
+                subMesh.setEffect(scene.getEngine().createEffect("grid", attribs, ["projection", "worldView", "mainColor", "lineColor", "gridControl", "gridOffset", "vFogInfos", "vFogColor", "world", "view"], [], join, undefined, this.onCompiled, this.onError), defines);
             }
             }
-            if (!subMesh.effect.isReady()) {
+            if (!subMesh.effect || !subMesh.effect.isReady()) {
                 return false;
                 return false;
             }
             }
             this._renderId = scene.getRenderId();
             this._renderId = scene.getRenderId();
@@ -3868,6 +3910,9 @@ var BABYLON;
                 return;
                 return;
             }
             }
             var effect = subMesh.effect;
             var effect = subMesh.effect;
+            if (!effect) {
+                return;
+            }
             this._activeEffect = effect;
             this._activeEffect = effect;
             // Matrices
             // Matrices
             this.bindOnlyWorldMatrix(world);
             this.bindOnlyWorldMatrix(world);
@@ -4493,7 +4538,7 @@ var BABYLON;
             // Attribs
             // Attribs
             BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true, true);
             BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true, true);
             // Values that need to be evaluated on every frame
             // Values that need to be evaluated on every frame
-            BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances);
+            BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false);
             // Get correct effect      
             // Get correct effect      
             if (defines.isDirty) {
             if (defines.isDirty) {
                 defines.markAsProcessed();
                 defines.markAsProcessed();
@@ -4600,7 +4645,7 @@ var BABYLON;
                 }, engine), defines);
                 }, engine), defines);
                 this.buildUniformLayout();
                 this.buildUniformLayout();
             }
             }
-            if (!subMesh.effect.isReady()) {
+            if (!subMesh.effect || !subMesh.effect.isReady()) {
                 return false;
                 return false;
             }
             }
             defines._renderId = scene.getRenderId();
             defines._renderId = scene.getRenderId();
@@ -4661,6 +4706,9 @@ var BABYLON;
                 return;
                 return;
             }
             }
             var effect = subMesh.effect;
             var effect = subMesh.effect;
+            if (!effect) {
+                return;
+            }
             this._activeEffect = effect;
             this._activeEffect = effect;
             // Matrices        
             // Matrices        
             this.bindOnlyWorldMatrix(world);
             this.bindOnlyWorldMatrix(world);
@@ -5880,11 +5928,14 @@ vColor=color;\n\
                 return this._createdShaderName;
                 return this._createdShaderName;
             this._isCreatedShader = false;
             this._isCreatedShader = false;
             CustomMaterial.ShaderIndexer++;
             CustomMaterial.ShaderIndexer++;
-            var name = name + "custom_" + CustomMaterial.ShaderIndexer;
+            var name = "custom_" + CustomMaterial.ShaderIndexer;
             this.ReviewUniform("uniform", uniforms);
             this.ReviewUniform("uniform", uniforms);
             this.ReviewUniform("sampler", samplers);
             this.ReviewUniform("sampler", samplers);
             var fn_afterBind = this._afterBind;
             var fn_afterBind = this._afterBind;
             this._afterBind = function (m, e) {
             this._afterBind = function (m, e) {
+                if (!e) {
+                    return;
+                }
                 _this.AttachAfterBind(m, e);
                 _this.AttachAfterBind(m, e);
                 try {
                 try {
                     fn_afterBind(m, e);
                     fn_afterBind(m, e);
@@ -6077,7 +6128,7 @@ var BABYLON;
             // Lights
             // Lights
             defines._needNormals = BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights, this._disableLighting);
             defines._needNormals = BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights, this._disableLighting);
             // Values that need to be evaluated on every frame
             // Values that need to be evaluated on every frame
-            BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances);
+            BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false);
             // Attribs
             // Attribs
             BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true);
             BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true);
             // Get correct effect      
             // Get correct effect      
@@ -6138,7 +6189,7 @@ var BABYLON;
                     indexParameters: { maxSimultaneousLights: this.maxSimultaneousLights - 1 }
                     indexParameters: { maxSimultaneousLights: this.maxSimultaneousLights - 1 }
                 }, engine), defines);
                 }, engine), defines);
             }
             }
-            if (!subMesh.effect.isReady()) {
+            if (!subMesh.effect || !subMesh.effect.isReady()) {
                 return false;
                 return false;
             }
             }
             this._renderId = scene.getRenderId();
             this._renderId = scene.getRenderId();
@@ -6152,6 +6203,9 @@ var BABYLON;
                 return;
                 return;
             }
             }
             var effect = subMesh.effect;
             var effect = subMesh.effect;
+            if (!effect) {
+                return;
+            }
             this._activeEffect = effect;
             this._activeEffect = effect;
             // Matrices        
             // Matrices        
             this.bindOnlyWorldMatrix(world);
             this.bindOnlyWorldMatrix(world);
@@ -6718,6 +6772,7 @@ var BABYLON;
         };
         };
         LegacyPBRMaterial.prototype.isReady = function (mesh, useInstances) {
         LegacyPBRMaterial.prototype.isReady = function (mesh, useInstances) {
             var _this = this;
             var _this = this;
+            if (mesh === void 0) { mesh = null; }
             if (this.isFrozen) {
             if (this.isFrozen) {
                 if (this._wasPreviouslyReady) {
                 if (this._wasPreviouslyReady) {
                     return true;
                     return true;
@@ -6727,10 +6782,10 @@ var BABYLON;
             var engine = scene.getEngine();
             var engine = scene.getEngine();
             var needUVs = false;
             var needUVs = false;
             this._defines.reset();
             this._defines.reset();
-            if (scene.lightsEnabled && !this.disableLighting) {
+            if (scene.lightsEnabled && !this.disableLighting && mesh) {
                 BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, this._defines, true, this.maxSimultaneousLights);
                 BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, this._defines, true, this.maxSimultaneousLights);
             }
             }
-            if (!this.checkReadyOnEveryCall) {
+            if (!this.checkReadyOnEveryCall && mesh) {
                 if (this._renderId === scene.getRenderId()) {
                 if (this._renderId === scene.getRenderId()) {
                     if (this._checkCache(scene, mesh, useInstances)) {
                     if (this._checkCache(scene, mesh, useInstances)) {
                         return true;
                         return true;
@@ -6998,14 +7053,14 @@ var BABYLON;
                 }
                 }
                 if (mesh.useBones && mesh.computeBonesUsingShaders) {
                 if (mesh.useBones && mesh.computeBonesUsingShaders) {
                     this._defines.NUM_BONE_INFLUENCERS = mesh.numBoneInfluencers;
                     this._defines.NUM_BONE_INFLUENCERS = mesh.numBoneInfluencers;
-                    this._defines.BonesPerMesh = (mesh.skeleton.bones.length + 1);
+                    this._defines.BonesPerMesh = (mesh.skeleton ? mesh.skeleton.bones.length + 1 : 0);
                 }
                 }
                 // Instances
                 // Instances
                 if (useInstances) {
                 if (useInstances) {
                     this._defines.INSTANCES = true;
                     this._defines.INSTANCES = true;
                 }
                 }
-                if (mesh.morphTargetManager) {
-                    var manager = mesh.morphTargetManager;
+                var manager = mesh.morphTargetManager;
+                if (manager) {
                     this._defines.MORPHTARGETS_TANGENT = manager.supportsTangents && this._defines.TANGENT;
                     this._defines.MORPHTARGETS_TANGENT = manager.supportsTangents && this._defines.TANGENT;
                     this._defines.MORPHTARGETS_NORMAL = manager.supportsNormals && this._defines.NORMAL;
                     this._defines.MORPHTARGETS_NORMAL = manager.supportsNormals && this._defines.NORMAL;
                     this._defines.MORPHTARGETS = (manager.numInfluencers > 0);
                     this._defines.MORPHTARGETS = (manager.numInfluencers > 0);
@@ -7081,9 +7136,11 @@ var BABYLON;
                 if (this._defines.VERTEXCOLOR) {
                 if (this._defines.VERTEXCOLOR) {
                     attribs.push(BABYLON.VertexBuffer.ColorKind);
                     attribs.push(BABYLON.VertexBuffer.ColorKind);
                 }
                 }
-                BABYLON.MaterialHelper.PrepareAttributesForBones(attribs, mesh, this._defines, fallbacks);
-                BABYLON.MaterialHelper.PrepareAttributesForInstances(attribs, this._defines);
-                BABYLON.MaterialHelper.PrepareAttributesForMorphTargets(attribs, mesh, this._defines);
+                if (mesh) {
+                    BABYLON.MaterialHelper.PrepareAttributesForBones(attribs, mesh, this._defines, fallbacks);
+                    BABYLON.MaterialHelper.PrepareAttributesForInstances(attribs, this._defines);
+                    BABYLON.MaterialHelper.PrepareAttributesForMorphTargets(attribs, mesh, this._defines);
+                }
                 // Legacy browser patch
                 // Legacy browser patch
                 var join = this._defines.toString();
                 var join = this._defines.toString();
                 var uniforms = ["world", "view", "viewProjection", "vEyePosition", "vLightsType", "vAmbientColor", "vAlbedoColor", "vReflectivityColor", "vEmissiveColor", "vReflectionColor",
                 var uniforms = ["world", "view", "viewProjection", "vEyePosition", "vLightsType", "vAmbientColor", "vAlbedoColor", "vReflectivityColor", "vEmissiveColor", "vReflectionColor",
@@ -7135,7 +7192,7 @@ var BABYLON;
                 }, engine);
                 }, engine);
                 this.buildUniformLayout();
                 this.buildUniformLayout();
             }
             }
-            if (!this._effect.isReady()) {
+            if (!this._effect || !this._effect.isReady()) {
                 return false;
                 return false;
             }
             }
             this._renderId = scene.getRenderId();
             this._renderId = scene.getRenderId();
@@ -7195,15 +7252,20 @@ var BABYLON;
             _super.prototype.unbind.call(this);
             _super.prototype.unbind.call(this);
         };
         };
         LegacyPBRMaterial.prototype.bindOnlyWorldMatrix = function (world) {
         LegacyPBRMaterial.prototype.bindOnlyWorldMatrix = function (world) {
-            this._effect.setMatrix("world", world);
+            if (this._effect) {
+                this._effect.setMatrix("world", world);
+            }
         };
         };
         LegacyPBRMaterial.prototype.bind = function (world, mesh) {
         LegacyPBRMaterial.prototype.bind = function (world, mesh) {
             this._myScene = this.getScene();
             this._myScene = this.getScene();
             var effect = this._effect;
             var effect = this._effect;
+            if (!effect) {
+                return;
+            }
             // Matrices        
             // Matrices        
             this.bindOnlyWorldMatrix(world);
             this.bindOnlyWorldMatrix(world);
             // Bones
             // Bones
-            BABYLON.MaterialHelper.BindBonesParameters(mesh, this._effect);
+            BABYLON.MaterialHelper.BindBonesParameters(mesh, effect);
             if (this._myScene.getCachedMaterial() !== this) {
             if (this._myScene.getCachedMaterial() !== this) {
                 this._uniformBuffer.bindToEffect(effect, "Material");
                 this._uniformBuffer.bindToEffect(effect, "Material");
                 this.bindViewProjection(effect);
                 this.bindViewProjection(effect);
@@ -7238,15 +7300,17 @@ var BABYLON;
                             this._uniformBuffer.updateFloat2("vReflectionInfos", this.reflectionTexture.level, 0);
                             this._uniformBuffer.updateFloat2("vReflectionInfos", this.reflectionTexture.level, 0);
                             if (this._defines.USESPHERICALFROMREFLECTIONMAP) {
                             if (this._defines.USESPHERICALFROMREFLECTIONMAP) {
                                 var polynomials = this.reflectionTexture.sphericalPolynomial;
                                 var polynomials = this.reflectionTexture.sphericalPolynomial;
-                                this._effect.setFloat3("vSphericalX", polynomials.x.x, polynomials.x.y, polynomials.x.z);
-                                this._effect.setFloat3("vSphericalY", polynomials.y.x, polynomials.y.y, polynomials.y.z);
-                                this._effect.setFloat3("vSphericalZ", polynomials.z.x, polynomials.z.y, polynomials.z.z);
-                                this._effect.setFloat3("vSphericalXX_ZZ", polynomials.xx.x - polynomials.zz.x, polynomials.xx.y - polynomials.zz.y, polynomials.xx.z - polynomials.zz.z);
-                                this._effect.setFloat3("vSphericalYY_ZZ", polynomials.yy.x - polynomials.zz.x, polynomials.yy.y - polynomials.zz.y, polynomials.yy.z - polynomials.zz.z);
-                                this._effect.setFloat3("vSphericalZZ", polynomials.zz.x, polynomials.zz.y, polynomials.zz.z);
-                                this._effect.setFloat3("vSphericalXY", polynomials.xy.x, polynomials.xy.y, polynomials.xy.z);
-                                this._effect.setFloat3("vSphericalYZ", polynomials.yz.x, polynomials.yz.y, polynomials.yz.z);
-                                this._effect.setFloat3("vSphericalZX", polynomials.zx.x, polynomials.zx.y, polynomials.zx.z);
+                                if (polynomials) {
+                                    effect.setFloat3("vSphericalX", polynomials.x.x, polynomials.x.y, polynomials.x.z);
+                                    effect.setFloat3("vSphericalY", polynomials.y.x, polynomials.y.y, polynomials.y.z);
+                                    effect.setFloat3("vSphericalZ", polynomials.z.x, polynomials.z.y, polynomials.z.z);
+                                    effect.setFloat3("vSphericalXX_ZZ", polynomials.xx.x - polynomials.zz.x, polynomials.xx.y - polynomials.zz.y, polynomials.xx.z - polynomials.zz.z);
+                                    effect.setFloat3("vSphericalYY_ZZ", polynomials.yy.x - polynomials.zz.x, polynomials.yy.y - polynomials.zz.y, polynomials.yy.z - polynomials.zz.z);
+                                    effect.setFloat3("vSphericalZZ", polynomials.zz.x, polynomials.zz.y, polynomials.zz.z);
+                                    effect.setFloat3("vSphericalXY", polynomials.xy.x, polynomials.xy.y, polynomials.xy.z);
+                                    effect.setFloat3("vSphericalYZ", polynomials.yz.x, polynomials.yz.y, polynomials.yz.z);
+                                    effect.setFloat3("vSphericalZX", polynomials.zx.x, polynomials.zx.y, polynomials.zx.z);
+                                }
                             }
                             }
                         }
                         }
                         if (this.emissiveTexture && BABYLON.StandardMaterial.EmissiveTextureEnabled) {
                         if (this.emissiveTexture && BABYLON.StandardMaterial.EmissiveTextureEnabled) {
@@ -7319,7 +7383,9 @@ var BABYLON;
                     this._uniformBuffer.updateColor3("vReflectionColor", LegacyPBRMaterial._scaledReflection);
                     this._uniformBuffer.updateColor3("vReflectionColor", LegacyPBRMaterial._scaledReflection);
                     // GAMMA CORRECTION.
                     // GAMMA CORRECTION.
                     this.convertColorToLinearSpaceToRef(this.albedoColor, LegacyPBRMaterial._scaledAlbedo);
                     this.convertColorToLinearSpaceToRef(this.albedoColor, LegacyPBRMaterial._scaledAlbedo);
-                    this._uniformBuffer.updateColor4("vAlbedoColor", LegacyPBRMaterial._scaledAlbedo, this.alpha * mesh.visibility);
+                    if (mesh) {
+                        this._uniformBuffer.updateColor4("vAlbedoColor", LegacyPBRMaterial._scaledAlbedo, this.alpha * mesh.visibility);
+                    }
                     // Misc
                     // Misc
                     this._lightingInfos.x = this.directIntensity;
                     this._lightingInfos.x = this.directIntensity;
                     this._lightingInfos.y = this.emissiveIntensity;
                     this._lightingInfos.y = this.emissiveIntensity;
@@ -7397,51 +7463,51 @@ var BABYLON;
                         }
                         }
                     }
                     }
                     if (this.cameraColorGradingTexture && BABYLON.StandardMaterial.ColorGradingTextureEnabled) {
                     if (this.cameraColorGradingTexture && BABYLON.StandardMaterial.ColorGradingTextureEnabled) {
-                        this._effect.setTexture("cameraColorGrading2DSampler", this.cameraColorGradingTexture);
+                        effect.setTexture("cameraColorGrading2DSampler", this.cameraColorGradingTexture);
                         var x = this.cameraColorGradingTexture.level; // Texture Level
                         var x = this.cameraColorGradingTexture.level; // Texture Level
                         var y = this.cameraColorGradingTexture.getSize().height; // Texture Size example with 8
                         var y = this.cameraColorGradingTexture.getSize().height; // Texture Size example with 8
                         var z = y - 1.0; // SizeMinusOne 8 - 1
                         var z = y - 1.0; // SizeMinusOne 8 - 1
                         var w = 1 / y; // Space of 1 slice 1 / 8
                         var w = 1 / y; // Space of 1 slice 1 / 8
-                        this._effect.setFloat4("vCameraColorGradingInfos", x, y, z, w);
+                        effect.setFloat4("vCameraColorGradingInfos", x, y, z, w);
                         var slicePixelSizeU = w / y; // Space of 1 pixel in U direction, e.g. 1/64
                         var slicePixelSizeU = w / y; // Space of 1 pixel in U direction, e.g. 1/64
                         var slicePixelSizeV = w; // Space of 1 pixel in V direction, e.g. 1/8					    // Space of 1 pixel in V direction, e.g. 1/8
                         var slicePixelSizeV = w; // Space of 1 pixel in V direction, e.g. 1/8					    // Space of 1 pixel in V direction, e.g. 1/8
                         var x2 = z * slicePixelSizeU; // Extent of lookup range in U for a single slice so that range corresponds to (size-1) texels, for example 7/64
                         var x2 = z * slicePixelSizeU; // Extent of lookup range in U for a single slice so that range corresponds to (size-1) texels, for example 7/64
                         var y2 = z / y; // Extent of lookup range in V for a single slice so that range corresponds to (size-1) texels, for example 7/8
                         var y2 = z / y; // Extent of lookup range in V for a single slice so that range corresponds to (size-1) texels, for example 7/8
                         var z2 = 0.5 * slicePixelSizeU; // Offset of lookup range in U to align sample position with texel centre, for example 0.5/64 
                         var z2 = 0.5 * slicePixelSizeU; // Offset of lookup range in U to align sample position with texel centre, for example 0.5/64 
                         var w2 = 0.5 * slicePixelSizeV; // Offset of lookup range in V to align sample position with texel centre, for example 0.5/8
                         var w2 = 0.5 * slicePixelSizeV; // Offset of lookup range in V to align sample position with texel centre, for example 0.5/8
-                        this._effect.setFloat4("vCameraColorGradingScaleOffset", x2, y2, z2, w2);
+                        effect.setFloat4("vCameraColorGradingScaleOffset", x2, y2, z2, w2);
                     }
                     }
                 }
                 }
                 // Clip plane
                 // Clip plane
-                BABYLON.MaterialHelper.BindClipPlane(this._effect, this._myScene);
+                BABYLON.MaterialHelper.BindClipPlane(effect, this._myScene);
                 // Colors
                 // Colors
                 this._myScene.ambientColor.multiplyToRef(this.ambientColor, this._globalAmbientColor);
                 this._myScene.ambientColor.multiplyToRef(this.ambientColor, this._globalAmbientColor);
                 effect.setVector3("vEyePosition", this._myScene._mirroredCameraPosition ? this._myScene._mirroredCameraPosition : this._myScene.activeCamera.position);
                 effect.setVector3("vEyePosition", this._myScene._mirroredCameraPosition ? this._myScene._mirroredCameraPosition : this._myScene.activeCamera.position);
                 effect.setColor3("vAmbientColor", this._globalAmbientColor);
                 effect.setColor3("vAmbientColor", this._globalAmbientColor);
             }
             }
-            if (this._myScene.getCachedMaterial() !== this || !this.isFrozen) {
+            if (mesh && (this._myScene.getCachedMaterial() !== this || !this.isFrozen)) {
                 // Lights
                 // Lights
                 if (this._myScene.lightsEnabled && !this.disableLighting) {
                 if (this._myScene.lightsEnabled && !this.disableLighting) {
-                    LegacyPBRMaterial.BindLights(this._myScene, mesh, this._effect, this._defines, this.useScalarInLinearSpace, this.maxSimultaneousLights, this.usePhysicalLightFalloff);
+                    LegacyPBRMaterial.BindLights(this._myScene, mesh, effect, this._defines, this.useScalarInLinearSpace, this.maxSimultaneousLights, this.usePhysicalLightFalloff);
                 }
                 }
                 // View
                 // View
                 if (this._myScene.fogEnabled && mesh.applyFog && this._myScene.fogMode !== BABYLON.Scene.FOGMODE_NONE || this.reflectionTexture) {
                 if (this._myScene.fogEnabled && mesh.applyFog && this._myScene.fogMode !== BABYLON.Scene.FOGMODE_NONE || this.reflectionTexture) {
                     this.bindView(effect);
                     this.bindView(effect);
                 }
                 }
                 // Fog
                 // Fog
-                BABYLON.MaterialHelper.BindFogParameters(this._myScene, mesh, this._effect);
+                BABYLON.MaterialHelper.BindFogParameters(this._myScene, mesh, effect);
                 // Morph targets
                 // Morph targets
                 if (this._defines.NUM_MORPH_INFLUENCERS) {
                 if (this._defines.NUM_MORPH_INFLUENCERS) {
-                    BABYLON.MaterialHelper.BindMorphTargetParameters(mesh, this._effect);
+                    BABYLON.MaterialHelper.BindMorphTargetParameters(mesh, effect);
                 }
                 }
                 this._cameraInfos.x = this.cameraExposure;
                 this._cameraInfos.x = this.cameraExposure;
                 this._cameraInfos.y = this.cameraContrast;
                 this._cameraInfos.y = this.cameraContrast;
                 effect.setVector4("vCameraInfos", this._cameraInfos);
                 effect.setVector4("vCameraInfos", this._cameraInfos);
                 if (this.cameraColorCurves) {
                 if (this.cameraColorCurves) {
-                    BABYLON.ColorCurves.Bind(this.cameraColorCurves, this._effect);
+                    BABYLON.ColorCurves.Bind(this.cameraColorCurves, effect);
                 }
                 }
                 // Log. depth
                 // Log. depth
-                BABYLON.MaterialHelper.BindLogDepth(this._defines, this._effect, this._myScene);
+                BABYLON.MaterialHelper.BindLogDepth(this._defines, effect, this._myScene);
             }
             }
             this._uniformBuffer.update();
             this._uniformBuffer.update();
             this._afterBind(mesh);
             this._afterBind(mesh);
@@ -8066,7 +8132,7 @@ var BABYLON;
              * Sets the Color Grading 2D Lookup Texture.
              * Sets the Color Grading 2D Lookup Texture.
              */
              */
             set: function (value) {
             set: function (value) {
-                this._imageProcessingConfiguration.colorGradingTexture = value;
+                this.imageProcessingConfiguration.colorGradingTexture = value;
             },
             },
             enumerable: true,
             enumerable: true,
             configurable: true
             configurable: true
@@ -8079,7 +8145,7 @@ var BABYLON;
              * corresponding to low luminance, medium luminance, and high luminance areas respectively.
              * corresponding to low luminance, medium luminance, and high luminance areas respectively.
              */
              */
             get: function () {
             get: function () {
-                return this._imageProcessingConfiguration.colorCurves;
+                return this.imageProcessingConfiguration.colorCurves;
             },
             },
             /**
             /**
              * The color grading curves provide additional color adjustmnent that is applied after any color grading transform (3D LUT).
              * The color grading curves provide additional color adjustmnent that is applied after any color grading transform (3D LUT).
@@ -8088,7 +8154,7 @@ var BABYLON;
              * corresponding to low luminance, medium luminance, and high luminance areas respectively.
              * corresponding to low luminance, medium luminance, and high luminance areas respectively.
              */
              */
             set: function (value) {
             set: function (value) {
-                this._imageProcessingConfiguration.colorCurves = value;
+                this.imageProcessingConfiguration.colorCurves = value;
             },
             },
             enumerable: true,
             enumerable: true,
             configurable: true
             configurable: true
@@ -8269,7 +8335,7 @@ var BABYLON;
                 }, engine), defines);
                 }, engine), defines);
                 this.buildUniformLayout();
                 this.buildUniformLayout();
             }
             }
-            if (!subMesh.effect.isReady()) {
+            if (!subMesh.effect || !subMesh.effect.isReady()) {
                 return false;
                 return false;
             }
             }
             defines._renderId = scene.getRenderId();
             defines._renderId = scene.getRenderId();
@@ -8324,6 +8390,9 @@ var BABYLON;
                 return;
                 return;
             }
             }
             var effect = subMesh.effect;
             var effect = subMesh.effect;
+            if (!effect) {
+                return;
+            }
             this._activeEffect = effect;
             this._activeEffect = effect;
             // Matrices
             // Matrices
             this.bindOnlyWorldMatrix(world);
             this.bindOnlyWorldMatrix(world);
@@ -8396,7 +8465,6 @@ var BABYLON;
             }
             }
             this._uniformBuffer.update();
             this._uniformBuffer.update();
             this._afterBind(mesh);
             this._afterBind(mesh);
-            scene = null;
         };
         };
         /**
         /**
          * Dispose the material.
          * Dispose the material.

File diff suppressed because it is too large
+ 9 - 9
dist/preview release/materialsLibrary/babylonjs.materials.min.js


+ 22 - 22
dist/preview release/materialsLibrary/babylonjs.materials.module.d.ts

@@ -11,7 +11,7 @@ declare module BABYLON {
         constructor(name: string, scene: Scene);
         constructor(name: string, scene: Scene);
         needAlphaBlending(): boolean;
         needAlphaBlending(): boolean;
         needAlphaTesting(): boolean;
         needAlphaTesting(): boolean;
-        getAlphaTestTexture(): BaseTexture;
+        getAlphaTestTexture(): Nullable<BaseTexture>;
         activeLight: IShadowLight;
         activeLight: IShadowLight;
         isReadyForSubMesh(mesh: AbstractMesh, subMesh: SubMesh, useInstances?: boolean): boolean;
         isReadyForSubMesh(mesh: AbstractMesh, subMesh: SubMesh, useInstances?: boolean): boolean;
         bindForSubMesh(world: Matrix, mesh: Mesh, subMesh: SubMesh): void;
         bindForSubMesh(world: Matrix, mesh: Mesh, subMesh: SubMesh): void;
@@ -39,7 +39,7 @@ declare module BABYLON {
         constructor(name: string, scene: Scene);
         constructor(name: string, scene: Scene);
         needAlphaBlending(): boolean;
         needAlphaBlending(): boolean;
         needAlphaTesting(): boolean;
         needAlphaTesting(): boolean;
-        getAlphaTestTexture(): BaseTexture;
+        getAlphaTestTexture(): Nullable<BaseTexture>;
         isReadyForSubMesh(mesh: AbstractMesh, subMesh: SubMesh, useInstances?: boolean): boolean;
         isReadyForSubMesh(mesh: AbstractMesh, subMesh: SubMesh, useInstances?: boolean): boolean;
         bindForSubMesh(world: Matrix, mesh: Mesh, subMesh: SubMesh): void;
         bindForSubMesh(world: Matrix, mesh: Mesh, subMesh: SubMesh): void;
         getAnimatables(): IAnimatable[];
         getAnimatables(): IAnimatable[];
@@ -65,7 +65,7 @@ declare module BABYLON {
         constructor(name: string, scene: Scene);
         constructor(name: string, scene: Scene);
         needAlphaBlending(): boolean;
         needAlphaBlending(): boolean;
         needAlphaTesting(): boolean;
         needAlphaTesting(): boolean;
-        getAlphaTestTexture(): BaseTexture;
+        getAlphaTestTexture(): Nullable<BaseTexture>;
         isReadyForSubMesh(mesh: AbstractMesh, subMesh: SubMesh, useInstances?: boolean): boolean;
         isReadyForSubMesh(mesh: AbstractMesh, subMesh: SubMesh, useInstances?: boolean): boolean;
         bindForSubMesh(world: Matrix, mesh: Mesh, subMesh: SubMesh): void;
         bindForSubMesh(world: Matrix, mesh: Mesh, subMesh: SubMesh): void;
         getAnimatables(): IAnimatable[];
         getAnimatables(): IAnimatable[];
@@ -101,7 +101,7 @@ declare module BABYLON {
         constructor(name: string, scene: Scene);
         constructor(name: string, scene: Scene);
         needAlphaBlending(): boolean;
         needAlphaBlending(): boolean;
         needAlphaTesting(): boolean;
         needAlphaTesting(): boolean;
-        getAlphaTestTexture(): BaseTexture;
+        getAlphaTestTexture(): Nullable<BaseTexture>;
         isReadyForSubMesh(mesh: AbstractMesh, subMesh: SubMesh, useInstances?: boolean): boolean;
         isReadyForSubMesh(mesh: AbstractMesh, subMesh: SubMesh, useInstances?: boolean): boolean;
         bindForSubMesh(world: Matrix, mesh: Mesh, subMesh: SubMesh): void;
         bindForSubMesh(world: Matrix, mesh: Mesh, subMesh: SubMesh): void;
         getAnimatables(): IAnimatable[];
         getAnimatables(): IAnimatable[];
@@ -129,7 +129,7 @@ declare module BABYLON {
         constructor(name: string, scene: Scene);
         constructor(name: string, scene: Scene);
         needAlphaBlending(): boolean;
         needAlphaBlending(): boolean;
         needAlphaTesting(): boolean;
         needAlphaTesting(): boolean;
-        getAlphaTestTexture(): BaseTexture;
+        getAlphaTestTexture(): Nullable<BaseTexture>;
         isReadyForSubMesh(mesh: AbstractMesh, subMesh: SubMesh, useInstances?: boolean): boolean;
         isReadyForSubMesh(mesh: AbstractMesh, subMesh: SubMesh, useInstances?: boolean): boolean;
         bindForSubMesh(world: Matrix, mesh: Mesh, subMesh: SubMesh): void;
         bindForSubMesh(world: Matrix, mesh: Mesh, subMesh: SubMesh): void;
         getAnimatables(): IAnimatable[];
         getAnimatables(): IAnimatable[];
@@ -229,11 +229,11 @@ declare module BABYLON {
         readonly reflectionTexture: RenderTargetTexture;
         readonly reflectionTexture: RenderTargetTexture;
         addToRenderList(node: any): void;
         addToRenderList(node: any): void;
         enableRenderTargets(enable: boolean): void;
         enableRenderTargets(enable: boolean): void;
-        getRenderList(): AbstractMesh[];
+        getRenderList(): Nullable<AbstractMesh[]>;
         readonly renderTargetsEnabled: boolean;
         readonly renderTargetsEnabled: boolean;
         needAlphaBlending(): boolean;
         needAlphaBlending(): boolean;
         needAlphaTesting(): boolean;
         needAlphaTesting(): boolean;
-        getAlphaTestTexture(): BaseTexture;
+        getAlphaTestTexture(): Nullable<BaseTexture>;
         isReadyForSubMesh(mesh: AbstractMesh, subMesh: SubMesh, useInstances?: boolean): boolean;
         isReadyForSubMesh(mesh: AbstractMesh, subMesh: SubMesh, useInstances?: boolean): boolean;
         bindForSubMesh(world: Matrix, mesh: Mesh, subMesh: SubMesh): void;
         bindForSubMesh(world: Matrix, mesh: Mesh, subMesh: SubMesh): void;
         private _createRenderTargets(scene, renderTargetSize);
         private _createRenderTargets(scene, renderTargetSize);
@@ -253,11 +253,11 @@ declare module BABYLON {
 declare module BABYLON {
 declare module BABYLON {
     class FireMaterial extends PushMaterial {
     class FireMaterial extends PushMaterial {
         private _diffuseTexture;
         private _diffuseTexture;
-        diffuseTexture: BaseTexture;
+        diffuseTexture: Nullable<BaseTexture>;
         private _distortionTexture;
         private _distortionTexture;
-        distortionTexture: BaseTexture;
+        distortionTexture: Nullable<BaseTexture>;
         private _opacityTexture;
         private _opacityTexture;
-        opacityTexture: BaseTexture;
+        opacityTexture: Nullable<BaseTexture>;
         diffuseColor: Color3;
         diffuseColor: Color3;
         speed: number;
         speed: number;
         private _scaledDiffuse;
         private _scaledDiffuse;
@@ -266,7 +266,7 @@ declare module BABYLON {
         constructor(name: string, scene: Scene);
         constructor(name: string, scene: Scene);
         needAlphaBlending(): boolean;
         needAlphaBlending(): boolean;
         needAlphaTesting(): boolean;
         needAlphaTesting(): boolean;
-        getAlphaTestTexture(): BaseTexture;
+        getAlphaTestTexture(): Nullable<BaseTexture>;
         isReadyForSubMesh(mesh: AbstractMesh, subMesh: SubMesh, useInstances?: boolean): boolean;
         isReadyForSubMesh(mesh: AbstractMesh, subMesh: SubMesh, useInstances?: boolean): boolean;
         bindForSubMesh(world: Matrix, mesh: Mesh, subMesh: SubMesh): void;
         bindForSubMesh(world: Matrix, mesh: Mesh, subMesh: SubMesh): void;
         getAnimatables(): IAnimatable[];
         getAnimatables(): IAnimatable[];
@@ -309,7 +309,7 @@ declare module BABYLON {
         furTime: number;
         furTime: number;
         needAlphaBlending(): boolean;
         needAlphaBlending(): boolean;
         needAlphaTesting(): boolean;
         needAlphaTesting(): boolean;
-        getAlphaTestTexture(): BaseTexture;
+        getAlphaTestTexture(): Nullable<BaseTexture>;
         updateFur(): void;
         updateFur(): void;
         isReadyForSubMesh(mesh: AbstractMesh, subMesh: SubMesh, useInstances?: boolean): boolean;
         isReadyForSubMesh(mesh: AbstractMesh, subMesh: SubMesh, useInstances?: boolean): boolean;
         bindForSubMesh(world: Matrix, mesh: Mesh, subMesh: SubMesh): void;
         bindForSubMesh(world: Matrix, mesh: Mesh, subMesh: SubMesh): void;
@@ -354,7 +354,7 @@ declare module BABYLON {
         constructor(name: string, scene: Scene);
         constructor(name: string, scene: Scene);
         needAlphaBlending(): boolean;
         needAlphaBlending(): boolean;
         needAlphaTesting(): boolean;
         needAlphaTesting(): boolean;
-        getAlphaTestTexture(): BaseTexture;
+        getAlphaTestTexture(): Nullable<BaseTexture>;
         isReadyForSubMesh(mesh: AbstractMesh, subMesh: SubMesh, useInstances?: boolean): boolean;
         isReadyForSubMesh(mesh: AbstractMesh, subMesh: SubMesh, useInstances?: boolean): boolean;
         bindForSubMesh(world: Matrix, mesh: Mesh, subMesh: SubMesh): void;
         bindForSubMesh(world: Matrix, mesh: Mesh, subMesh: SubMesh): void;
         getAnimatables(): IAnimatable[];
         getAnimatables(): IAnimatable[];
@@ -396,7 +396,7 @@ declare module BABYLON {
         constructor(name: string, scene: Scene);
         constructor(name: string, scene: Scene);
         needAlphaBlending(): boolean;
         needAlphaBlending(): boolean;
         needAlphaTesting(): boolean;
         needAlphaTesting(): boolean;
-        getAlphaTestTexture(): BaseTexture;
+        getAlphaTestTexture(): Nullable<BaseTexture>;
         isReadyForSubMesh(mesh: AbstractMesh, subMesh: SubMesh, useInstances?: boolean): boolean;
         isReadyForSubMesh(mesh: AbstractMesh, subMesh: SubMesh, useInstances?: boolean): boolean;
         bindForSubMesh(world: Matrix, mesh: Mesh, subMesh: SubMesh): void;
         bindForSubMesh(world: Matrix, mesh: Mesh, subMesh: SubMesh): void;
         getAnimatables(): IAnimatable[];
         getAnimatables(): IAnimatable[];
@@ -428,7 +428,7 @@ declare module BABYLON {
         constructor(name: string, scene: Scene);
         constructor(name: string, scene: Scene);
         needAlphaBlending(): boolean;
         needAlphaBlending(): boolean;
         needAlphaTesting(): boolean;
         needAlphaTesting(): boolean;
-        getAlphaTestTexture(): BaseTexture;
+        getAlphaTestTexture(): Nullable<BaseTexture>;
         isReadyForSubMesh(mesh: AbstractMesh, subMesh: SubMesh, useInstances?: boolean): boolean;
         isReadyForSubMesh(mesh: AbstractMesh, subMesh: SubMesh, useInstances?: boolean): boolean;
         bindForSubMesh(world: Matrix, mesh: Mesh, subMesh: SubMesh): void;
         bindForSubMesh(world: Matrix, mesh: Mesh, subMesh: SubMesh): void;
         getAnimatables(): IAnimatable[];
         getAnimatables(): IAnimatable[];
@@ -678,7 +678,7 @@ declare module BABYLON {
          * Attaches a new image processing configuration to the Standard Material.
          * Attaches a new image processing configuration to the Standard Material.
          * @param configuration
          * @param configuration
          */
          */
-        protected _attachImageProcessingConfiguration(configuration: ImageProcessingConfiguration): void;
+        protected _attachImageProcessingConfiguration(configuration: Nullable<ImageProcessingConfiguration>): void;
         /**
         /**
          * Gets wether the color curves effect is enabled.
          * Gets wether the color curves effect is enabled.
          */
          */
@@ -724,7 +724,7 @@ declare module BABYLON {
         /**
         /**
          * Sets the Color Grading 2D Lookup Texture.
          * Sets the Color Grading 2D Lookup Texture.
          */
          */
-        cameraColorGradingTexture: BaseTexture;
+        cameraColorGradingTexture: Nullable<BaseTexture>;
         customShaderNameResolve: (shaderName: string, uniforms: string[], uniformBuffers: string[], samplers: string[], defines: StandardMaterialDefines_OldVer) => string;
         customShaderNameResolve: (shaderName: string, uniforms: string[], uniformBuffers: string[], samplers: string[], defines: StandardMaterialDefines_OldVer) => string;
         protected _renderTargets: SmartArray<RenderTargetTexture>;
         protected _renderTargets: SmartArray<RenderTargetTexture>;
         protected _worldViewProjectionMatrix: Matrix;
         protected _worldViewProjectionMatrix: Matrix;
@@ -844,7 +844,7 @@ declare module BABYLON {
         constructor(name: string, scene: Scene);
         constructor(name: string, scene: Scene);
         needAlphaBlending(): boolean;
         needAlphaBlending(): boolean;
         needAlphaTesting(): boolean;
         needAlphaTesting(): boolean;
-        getAlphaTestTexture(): BaseTexture;
+        getAlphaTestTexture(): Nullable<BaseTexture>;
         isReadyForSubMesh(mesh: AbstractMesh, subMesh: SubMesh, useInstances?: boolean): boolean;
         isReadyForSubMesh(mesh: AbstractMesh, subMesh: SubMesh, useInstances?: boolean): boolean;
         bindForSubMesh(world: Matrix, mesh: Mesh, subMesh: SubMesh): void;
         bindForSubMesh(world: Matrix, mesh: Mesh, subMesh: SubMesh): void;
         getAnimatables(): IAnimatable[];
         getAnimatables(): IAnimatable[];
@@ -919,14 +919,14 @@ declare module BABYLON {
          * Color Grading 2D Lookup Texture.
          * Color Grading 2D Lookup Texture.
          * This allows special effects like sepia, black and white to sixties rendering style.
          * This allows special effects like sepia, black and white to sixties rendering style.
          */
          */
-        cameraColorGradingTexture: BaseTexture;
+        cameraColorGradingTexture: Nullable<BaseTexture>;
         /**
         /**
          * The color grading curves provide additional color adjustmnent that is applied after any color grading transform (3D LUT).
          * The color grading curves provide additional color adjustmnent that is applied after any color grading transform (3D LUT).
          * They allow basic adjustment of saturation and small exposure adjustments, along with color filter tinting to provide white balance adjustment or more stylistic effects.
          * They allow basic adjustment of saturation and small exposure adjustments, along with color filter tinting to provide white balance adjustment or more stylistic effects.
          * These are similar to controls found in many professional imaging or colorist software. The global controls are applied to the entire image. For advanced tuning, extra controls are provided to adjust the shadow, midtone and highlight areas of the image;
          * These are similar to controls found in many professional imaging or colorist software. The global controls are applied to the entire image. For advanced tuning, extra controls are provided to adjust the shadow, midtone and highlight areas of the image;
          * corresponding to low luminance, medium luminance, and high luminance areas respectively.
          * corresponding to low luminance, medium luminance, and high luminance areas respectively.
          */
          */
-        cameraColorCurves: ColorCurves;
+        cameraColorCurves: Nullable<ColorCurves>;
         private _cameraInfos;
         private _cameraInfos;
         private _microsurfaceTextureLods;
         private _microsurfaceTextureLods;
         /**
         /**
@@ -1180,7 +1180,7 @@ declare module BABYLON {
         private static _scaledEmissive;
         private static _scaledEmissive;
         private static _scaledReflection;
         private static _scaledReflection;
         static BindLights(scene: Scene, mesh: AbstractMesh, effect: Effect, defines: MaterialDefines, useScalarInLinearSpace: boolean, maxSimultaneousLights: number, usePhysicalLightFalloff: boolean): void;
         static BindLights(scene: Scene, mesh: AbstractMesh, effect: Effect, defines: MaterialDefines, useScalarInLinearSpace: boolean, maxSimultaneousLights: number, usePhysicalLightFalloff: boolean): void;
-        isReady(mesh?: AbstractMesh, useInstances?: boolean): boolean;
+        isReady(mesh?: Nullable<AbstractMesh>, useInstances?: boolean): boolean;
         buildUniformLayout(): void;
         buildUniformLayout(): void;
         unbind(): void;
         unbind(): void;
         bindOnlyWorldMatrix(world: Matrix): void;
         bindOnlyWorldMatrix(world: Matrix): void;
@@ -1304,7 +1304,7 @@ declare namespace BABYLON {
          *
          *
          * If sets to null, the scene one is in use.
          * If sets to null, the scene one is in use.
          */
          */
-        imageProcessingConfiguration: ImageProcessingConfiguration;
+        imageProcessingConfiguration: Nullable<ImageProcessingConfiguration>;
         /**
         /**
          * Gets wether the color curves effect is enabled.
          * Gets wether the color curves effect is enabled.
          */
          */

+ 76 - 30
gui/src/advancedDynamicTexture.ts

@@ -9,27 +9,27 @@ module BABYLON.GUI {
 
 
     export class AdvancedDynamicTexture extends DynamicTexture {
     export class AdvancedDynamicTexture extends DynamicTexture {
         private _isDirty = false;
         private _isDirty = false;
-        private _renderObserver: Observer<Camera>;
-        private _resizeObserver: Observer<Engine>;
-        private _preKeyboardObserver: Observer<KeyboardInfoPre>;
-        private _pointerMoveObserver: Observer<PointerInfoPre>;
-        private _pointerObserver: Observer<PointerInfo>;
-        private _canvasPointerOutObserver: Observer<Engine>;
+        private _renderObserver: Nullable<Observer<Camera>>;
+        private _resizeObserver: Nullable<Observer<Engine>>;
+        private _preKeyboardObserver: Nullable<Observer<KeyboardInfoPre>>;
+        private _pointerMoveObserver: Nullable<Observer<PointerInfoPre>>;
+        private _pointerObserver: Nullable<Observer<PointerInfo>>;
+        private _canvasPointerOutObserver: Nullable<Observer<Engine>>;
         private _background: string;
         private _background: string;
         public _rootContainer = new Container("root");
         public _rootContainer = new Container("root");
         public _lastPickedControl: Control;
         public _lastPickedControl: Control;
-        public _lastControlOver: Control;
-        public _lastControlDown: Control;
-        public _capturingControl: Control;
+        public _lastControlOver: Nullable<Control>;
+        public _lastControlDown: Nullable<Control>;
+        public _capturingControl: Nullable<Control>;
         public _shouldBlockPointer: boolean;
         public _shouldBlockPointer: boolean;
-        public _layerToDispose: Layer;
+        public _layerToDispose: Nullable<Layer>;
         public _linkedControls = new Array<Control>();
         public _linkedControls = new Array<Control>();
         private _isFullscreen = false;
         private _isFullscreen = false;
         private _fullscreenViewport = new Viewport(0, 0, 1, 1);
         private _fullscreenViewport = new Viewport(0, 0, 1, 1);
         private _idealWidth = 0;
         private _idealWidth = 0;
         private _idealHeight = 0;
         private _idealHeight = 0;
         private _renderAtIdealSize = false;
         private _renderAtIdealSize = false;
-        private _focusedControl: IFocusableControl;
+        private _focusedControl: Nullable<IFocusableControl>;
         private _blockNextFocusCheck = false;
         private _blockNextFocusCheck = false;
 
 
         public get background(): string {
         public get background(): string {
@@ -86,7 +86,7 @@ module BABYLON.GUI {
             this._onResize();
             this._onResize();
         }    
         }    
 
 
-        public get layer(): Layer {
+        public get layer(): Nullable<Layer> {
             return this._layerToDispose;
             return this._layerToDispose;
         }   
         }   
 
 
@@ -94,11 +94,11 @@ module BABYLON.GUI {
             return this._rootContainer;
             return this._rootContainer;
         }
         }
 
 
-        public get focusedControl(): IFocusableControl {
+        public get focusedControl(): Nullable<IFocusableControl> {
             return this._focusedControl;
             return this._focusedControl;
         }
         }
 
 
-        public set focusedControl(control: IFocusableControl) {
+        public set focusedControl(control: Nullable<IFocusableControl>) {
             if (this._focusedControl == control) {
             if (this._focusedControl == control) {
                 return;
                 return;
             }
             }
@@ -114,11 +114,17 @@ module BABYLON.GUI {
             this._focusedControl = control;
             this._focusedControl = control;
         }
         }
        
        
-        constructor(name: string, width = 0, height = 0, scene: Scene, generateMipMaps = false, samplingMode = Texture.NEAREST_SAMPLINGMODE) {
+        constructor(name: string, width = 0, height = 0, scene: Nullable<Scene>, generateMipMaps = false, samplingMode = Texture.NEAREST_SAMPLINGMODE) {
             super(name, {width: width, height: height}, scene, generateMipMaps, samplingMode, Engine.TEXTUREFORMAT_RGBA);
             super(name, {width: width, height: height}, scene, generateMipMaps, samplingMode, Engine.TEXTUREFORMAT_RGBA);
 
 
-            this._renderObserver = this.getScene().onBeforeCameraRenderObservable.add((camera: Camera) => this._checkUpdate(camera));
-            this._preKeyboardObserver = this.getScene().onPreKeyboardObservable.add(info => {
+            scene = this.getScene();
+
+            if (!scene || !this._texture) {
+                return;
+            }
+
+            this._renderObserver = scene.onBeforeCameraRenderObservable.add((camera: Camera) => this._checkUpdate(camera));
+            this._preKeyboardObserver = scene.onPreKeyboardObservable.add(info => {
                 if (!this._focusedControl) {
                 if (!this._focusedControl) {
                     return;
                     return;
                 }
                 }
@@ -135,7 +141,7 @@ module BABYLON.GUI {
             this.hasAlpha = true;
             this.hasAlpha = true;
 
 
             if (!width || !height) {
             if (!width || !height) {
-                this._resizeObserver = this.getScene().getEngine().onResizeObservable.add(() => this._onResize());
+                this._resizeObserver = scene.getEngine().onResizeObservable.add(() => this._onResize());
                 this._onResize();
                 this._onResize();
             }
             }
 
 
@@ -171,23 +177,29 @@ module BABYLON.GUI {
             return this;
             return this;
         }
         }
 
 
-        public dispose() {
-            this.getScene().onBeforeCameraRenderObservable.remove(this._renderObserver);
+        public dispose(): void {
+            let scene = this.getScene();
+
+            if (!scene) {
+                return;
+            }
+
+            scene.onBeforeCameraRenderObservable.remove(this._renderObserver);
 
 
             if (this._resizeObserver) {
             if (this._resizeObserver) {
-                this.getScene().getEngine().onResizeObservable.remove(this._resizeObserver);
+                scene.getEngine().onResizeObservable.remove(this._resizeObserver);
             }
             }
 
 
             if (this._pointerMoveObserver) {
             if (this._pointerMoveObserver) {
-                this.getScene().onPrePointerObservable.remove(this._pointerMoveObserver);
+                scene.onPrePointerObservable.remove(this._pointerMoveObserver);
             }
             }
 
 
             if (this._pointerObserver) {
             if (this._pointerObserver) {
-                this.getScene().onPointerObservable.remove(this._pointerObserver);
+                scene.onPointerObservable.remove(this._pointerObserver);
             }
             }
 
 
             if (this._canvasPointerOutObserver) {
             if (this._canvasPointerOutObserver) {
-                this.getScene().getEngine().onCanvasPointerOutObservable.remove(this._canvasPointerOutObserver);
+                scene.getEngine().onCanvasPointerOutObservable.remove(this._canvasPointerOutObserver);
             }
             }
 
 
             if (this._layerToDispose) {
             if (this._layerToDispose) {
@@ -202,8 +214,14 @@ module BABYLON.GUI {
         }
         }
 
 
         private _onResize(): void {
         private _onResize(): void {
+            let scene = this.getScene();
+            
+            if (!scene) {
+                return;
+            }            
+
             // Check size
             // Check size
-            var engine = this.getScene().getEngine();
+            var engine = scene.getEngine();
             var textureSize = this.getSize();
             var textureSize = this.getSize();
             var renderWidth = engine.getRenderWidth();
             var renderWidth = engine.getRenderWidth();
             var renderHeight = engine.getRenderHeight();
             var renderHeight = engine.getRenderHeight();
@@ -243,6 +261,11 @@ module BABYLON.GUI {
 
 
             if (this._isFullscreen && this._linkedControls.length) {
             if (this._isFullscreen && this._linkedControls.length) {
                 var scene = this.getScene();
                 var scene = this.getScene();
+
+                if (!scene) {
+                    return;
+                }
+
                 var globalViewport = this._getGlobalViewport(scene);
                 var globalViewport = this._getGlobalViewport(scene);
 
 
                 for (var control of this._linkedControls) {
                 for (var control of this._linkedControls) {
@@ -260,7 +283,7 @@ module BABYLON.GUI {
                         continue;
                         continue;
                     }
                     }
                     
                     
-                    var position = mesh.getBoundingInfo().boundingSphere.center;
+                    var position = (<BoundingInfo>mesh.getBoundingInfo()).boundingSphere.center;
                     var projectedPosition = Vector3.Project(position, mesh.getWorldMatrix(), scene.getTransformMatrix(), globalViewport);
                     var projectedPosition = Vector3.Project(position, mesh.getWorldMatrix(), scene.getTransformMatrix(), globalViewport);
 
 
                     if (projectedPosition.z < 0 || projectedPosition.z > 1) {
                     if (projectedPosition.z < 0 || projectedPosition.z > 1) {
@@ -305,6 +328,11 @@ module BABYLON.GUI {
 
 
         private _doPicking(x: number, y: number, type: number, buttonIndex: number): void {
         private _doPicking(x: number, y: number, type: number, buttonIndex: number): void {
             var scene = this.getScene();
             var scene = this.getScene();
+
+            if (!scene) {
+                return;
+            }
+
             var engine = scene.getEngine();
             var engine = scene.getEngine();
             var textureSize = this.getSize();
             var textureSize = this.getSize();
 
 
@@ -334,6 +362,10 @@ module BABYLON.GUI {
 
 
         public attach(): void {
         public attach(): void {
             var scene = this.getScene();
             var scene = this.getScene();
+            if (!scene) {
+                return;
+            }
+
             this._pointerMoveObserver = scene.onPrePointerObservable.add((pi, state) => {
             this._pointerMoveObserver = scene.onPrePointerObservable.add((pi, state) => {
                 if (pi.type !== BABYLON.PointerEventTypes.POINTERMOVE 
                 if (pi.type !== BABYLON.PointerEventTypes.POINTERMOVE 
                     && pi.type !== BABYLON.PointerEventTypes.POINTERUP
                     && pi.type !== BABYLON.PointerEventTypes.POINTERUP
@@ -341,7 +373,15 @@ module BABYLON.GUI {
                     return;
                     return;
                 }
                 }
 
 
+                if (!scene) {
+                    return;
+                }
+
                 let camera = scene.cameraToUseForPointers || scene.activeCamera;
                 let camera = scene.cameraToUseForPointers || scene.activeCamera;
+
+                if (!camera) {
+                    return;
+                }
                 let engine = scene.getEngine();
                 let engine = scene.getEngine();
                 let viewport = camera.viewport;
                 let viewport = camera.viewport;
                 let x = (scene.pointerX / engine.getHardwareScalingLevel() - viewport.x * engine.getRenderWidth()) / viewport.width;
                 let x = (scene.pointerX / engine.getHardwareScalingLevel() - viewport.x * engine.getRenderWidth()) / viewport.width;
@@ -358,6 +398,9 @@ module BABYLON.GUI {
 
 
         public attachToMesh(mesh: AbstractMesh, supportPointerMove = true): void {
         public attachToMesh(mesh: AbstractMesh, supportPointerMove = true): void {
             var scene = this.getScene();
             var scene = this.getScene();
+            if (!scene) {
+                return;
+            }            
             this._pointerObserver = scene.onPointerObservable.add((pi, state) => {
             this._pointerObserver = scene.onPointerObservable.add((pi, state) => {
                 if (pi.type !== BABYLON.PointerEventTypes.POINTERMOVE 
                 if (pi.type !== BABYLON.PointerEventTypes.POINTERMOVE 
                     && pi.type !== BABYLON.PointerEventTypes.POINTERUP
                     && pi.type !== BABYLON.PointerEventTypes.POINTERUP
@@ -365,10 +408,13 @@ module BABYLON.GUI {
                     return;
                     return;
                 }
                 }
 
 
-                if (pi.pickInfo.hit && pi.pickInfo.pickedMesh === mesh) {
+                if (pi.pickInfo && pi.pickInfo.hit && pi.pickInfo.pickedMesh === mesh) {
                     var uv = pi.pickInfo.getTextureCoordinates();
                     var uv = pi.pickInfo.getTextureCoordinates();
-                    var size = this.getSize();
-                    this._doPicking(uv.x * size.width, (1.0 - uv.y) * size.height, pi.type, pi.event.button);
+
+                    if (uv) {
+                        let size = this.getSize();
+                        this._doPicking(uv.x * size.width, (1.0 - uv.y) * size.height, pi.type, pi.event.button);
+                    }
                 } else if (pi.type === BABYLON.PointerEventTypes.POINTERUP) {
                 } else if (pi.type === BABYLON.PointerEventTypes.POINTERUP) {
                     if (this._lastControlDown) {
                     if (this._lastControlDown) {
                         this._lastControlDown.forcePointerUp();
                         this._lastControlDown.forcePointerUp();
@@ -445,7 +491,7 @@ module BABYLON.GUI {
             return result;
             return result;
         }
         }
 
 
-        public static CreateFullscreenUI(name: string, foreground: boolean = true, scene: Scene = null): AdvancedDynamicTexture {
+        public static CreateFullscreenUI(name: string, foreground: boolean = true, scene: Nullable<Scene> = null): AdvancedDynamicTexture {
             var result = new AdvancedDynamicTexture(name, 0, 0, scene);
             var result = new AdvancedDynamicTexture(name, 0, 0, scene);
 
 
             // Display
             // Display

+ 1 - 1
gui/src/controls/colorpicker.ts

@@ -128,7 +128,7 @@ module BABYLON.GUI {
             var canvas = document.createElement("canvas");
             var canvas = document.createElement("canvas");
             canvas.width = radius * 2;
             canvas.width = radius * 2;
             canvas.height = radius * 2;
             canvas.height = radius * 2;
-            var context = canvas.getContext("2d");
+            var context = <CanvasRenderingContext2D>canvas.getContext("2d");
             var image = context.getImageData(0, 0, radius * 2, radius * 2);
             var image = context.getImageData(0, 0, radius * 2, radius * 2);
             var data = image.data;
             var data = image.data;
             
             

+ 3 - 3
gui/src/controls/container.ts

@@ -31,7 +31,7 @@ module BABYLON.GUI {
             return "Container";
             return "Container";
         }           
         }           
 
 
-        public getChildByName(name: string): Control {
+        public getChildByName(name: string): Nullable<Control> {
             for (var child of this._children) {
             for (var child of this._children) {
                 if (child.name === name) {
                 if (child.name === name) {
                     return child;
                     return child;
@@ -41,7 +41,7 @@ module BABYLON.GUI {
             return null;
             return null;
         }       
         }       
 
 
-        public getChildByType(name: string, type: string): Control {
+        public getChildByType(name: string, type: string): Nullable<Control> {
             for (var child of this._children) {
             for (var child of this._children) {
                 if (child.typeName === type) {
                 if (child.typeName === type) {
                     return child;
                     return child;
@@ -124,7 +124,7 @@ module BABYLON.GUI {
             }
             }
         }
         }
 
 
-        public _link(root: Container, host: AdvancedDynamicTexture): void {
+        public _link(root: Nullable<Container>, host: AdvancedDynamicTexture): void {
             super._link(root, host);
             super._link(root, host);
 
 
             for (var child of this._children) {
             for (var child of this._children) {

+ 5 - 5
gui/src/controls/control.ts

@@ -5,9 +5,9 @@ module BABYLON.GUI {
         private _alpha = 1; 
         private _alpha = 1; 
         private _alphaSet = false; 
         private _alphaSet = false; 
         private _zIndex = 0;
         private _zIndex = 0;
-        public _root: Container;
+        public _root: Nullable<Container>;
         public _host: AdvancedDynamicTexture;
         public _host: AdvancedDynamicTexture;
-        public parent: Container;
+        public parent: Nullable<Container>;
         public _currentMeasure = Measure.Empty();
         public _currentMeasure = Measure.Empty();
         private _fontFamily = "Arial";
         private _fontFamily = "Arial";
         private _fontStyle = "";
         private _fontStyle = "";
@@ -39,7 +39,7 @@ module BABYLON.GUI {
         private _cachedOffsetX: number;
         private _cachedOffsetX: number;
         private _cachedOffsetY: number;
         private _cachedOffsetY: number;
         private _isVisible = true;
         private _isVisible = true;
-        public _linkedMesh: AbstractMesh;
+        public _linkedMesh: Nullable<AbstractMesh>;
         private _fontSet = false;
         private _fontSet = false;
         private _dummyVector2 = Vector2.Zero();
         private _dummyVector2 = Vector2.Zero();
         private _downCount = 0;
         private _downCount = 0;
@@ -522,7 +522,7 @@ module BABYLON.GUI {
             this.notRenderable = false;
             this.notRenderable = false;
         }
         }
 
 
-        public linkWithMesh(mesh: AbstractMesh): void {
+        public linkWithMesh(mesh: Nullable<AbstractMesh>): void {
             if (!this._host || this._root !== this._host._rootContainer) {
             if (!this._host || this._root !== this._host._rootContainer) {
                 Tools.Error("Cannot link a control to a mesh if the control is not at root level");
                 Tools.Error("Cannot link a control to a mesh if the control is not at root level");
                 return;
                 return;
@@ -573,7 +573,7 @@ module BABYLON.GUI {
             }
             }
         }
         }
 
 
-        public _link(root: Container, host: AdvancedDynamicTexture): void {
+        public _link(root: Nullable<Container>, host: AdvancedDynamicTexture): void {
             this._root = root;
             this._root = root;
             this._host = host;
             this._host = host;
         }
         }

+ 11 - 7
gui/src/controls/image.ts

@@ -9,7 +9,7 @@ module BABYLON.GUI {
         private _imageHeight: number;
         private _imageHeight: number;
         private _loaded = false;
         private _loaded = false;
         private _stretch = Image.STRETCH_FILL;
         private _stretch = Image.STRETCH_FILL;
-        private _source: string;
+        private _source: Nullable<string>;
         private _autoScale = false;
         private _autoScale = false;
 
 
         private _sourceLeft = 0;
         private _sourceLeft = 0;
@@ -132,7 +132,7 @@ module BABYLON.GUI {
             this._markAsDirty();
             this._markAsDirty();
         }
         }
 
 
-        public set source(value: string) {
+        public set source(value: Nullable<string>) {
             if (this._source === value) {
             if (this._source === value) {
                 return;
                 return;
             }
             }
@@ -145,11 +145,13 @@ module BABYLON.GUI {
             this._domImage.onload = () => {
             this._domImage.onload = () => {
                 this._onImageLoaded();
                 this._onImageLoaded();
             }
             }
-            this._domImage.crossOrigin = "anonymous";
-            this._domImage.src = value;
+            if (value) {
+                this._domImage.crossOrigin = "anonymous";
+                this._domImage.src = value;
+            }
         }
         }
 
 
-        constructor(public name?: string, url?: string) {
+        constructor(public name?: string, url: Nullable<string> = null) {
             super(name);
             super(name);
 
 
             this.source = url;
             this.source = url;
@@ -204,8 +206,10 @@ module BABYLON.GUI {
                             if (this._autoScale) {
                             if (this._autoScale) {
                                 this.synchronizeSizeWithContent();
                                 this.synchronizeSizeWithContent();
                             } 
                             } 
-                            this._root.width = this.width;
-                            this._root.height = this.height;
+                            if (this._root) {
+                                this._root.width = this.width;
+                                this._root.height = this.height;
+                            }
                             break;
                             break;
                     }
                     }
                 }
                 }

+ 2 - 2
gui/src/controls/inputText.ts

@@ -15,9 +15,9 @@ module BABYLON.GUI {
         private _blinkTimeout: number;
         private _blinkTimeout: number;
         private _blinkIsEven = false;
         private _blinkIsEven = false;
         private _cursorOffset = 0;        
         private _cursorOffset = 0;        
-        private _scrollLeft: number;
+        private _scrollLeft: Nullable<number>;
         private _textWidth: number;
         private _textWidth: number;
-        private _clickedCoordinate: number;
+        private _clickedCoordinate: Nullable<number>;
         
         
         public promptMessage = "Please enter text:";
         public promptMessage = "Please enter text:";
 
 

+ 1 - 1
gui/src/controls/line.ts

@@ -9,7 +9,7 @@ module BABYLON.GUI {
         private _y2 = new ValueAndUnit(0);
         private _y2 = new ValueAndUnit(0);
         private _dash = new Array<number>();
         private _dash = new Array<number>();
         private _connectedControl: Control;
         private _connectedControl: Control;
-        private _connectedControlDirtyObserver: Observer<Control>;
+        private _connectedControlDirtyObserver: Nullable<Observer<Control>>;
 
 
         public get dash(): Array<number> {
         public get dash(): Array<number> {
             return this._dash;
             return this._dash;

+ 9 - 6
gui/src/controls/virtualKeyboard.ts

@@ -31,7 +31,7 @@ module BABYLON.GUI {
             return "VirtualKeyboard";
             return "VirtualKeyboard";
         }
         }
 
 
-        private _createKey(key: string, propertySet?: KeyPropertySet) {
+        private _createKey(key: string, propertySet: Nullable<KeyPropertySet>) {
             var button = Button.CreateSimpleButton(key, key);
             var button = Button.CreateSimpleButton(key, key);
             
             
            
            
@@ -72,12 +72,12 @@ module BABYLON.GUI {
             this.addControl(panel);
             this.addControl(panel);
         }
         }
 
 
-        private _connectedInputText: InputText;
-        private _onFocusObserver: Observer<InputText>;
-        private _onBlurObserver: Observer<InputText>;
-        private _onKeyPressObserver: Observer<string>;
+        private _connectedInputText: Nullable<InputText>;
+        private _onFocusObserver: Nullable<Observer<InputText>>;
+        private _onBlurObserver: Nullable<Observer<InputText>>;
+        private _onKeyPressObserver: Nullable<Observer<string>>;
 
 
-        public get connectedInputText(): InputText {
+        public get connectedInputText(): Nullable<InputText> {
             return this._connectedInputText;
             return this._connectedInputText;
         }
         }
 
 
@@ -95,6 +95,9 @@ module BABYLON.GUI {
             });		
             });		
 
 
             this._onKeyPressObserver = this.onKeyPressObservable.add((key) => {
             this._onKeyPressObserver = this.onKeyPressObservable.add((key) => {
+                if (!this._connectedInputText) {
+                    return;
+                }
                 switch (key) {
                 switch (key) {
                     case "\u2190":
                     case "\u2190":
                         this._connectedInputText.processKey(8);
                         this._connectedInputText.processKey(8);

+ 1 - 1
gui/src/math2D.ts

@@ -101,7 +101,7 @@ module BABYLON.GUI {
         private static _TempCompose1 = Matrix2D.Identity();
         private static _TempCompose1 = Matrix2D.Identity();
         private static _TempCompose2 = Matrix2D.Identity();
         private static _TempCompose2 = Matrix2D.Identity();
 
 
-        public static ComposeToRef(tx: number, ty: number, angle: number, scaleX: number, scaleY: number, parentMatrix: Matrix2D,  result: Matrix2D): void {
+        public static ComposeToRef(tx: number, ty: number, angle: number, scaleX: number, scaleY: number, parentMatrix: Nullable<Matrix2D>,  result: Matrix2D): void {
             Matrix2D.TranslationToRef(tx, ty, Matrix2D._TempPreTranslationMatrix);
             Matrix2D.TranslationToRef(tx, ty, Matrix2D._TempPreTranslationMatrix);
 
 
             Matrix2D.ScalingToRef(scaleX, scaleY, Matrix2D._TempScalingMatrix);
             Matrix2D.ScalingToRef(scaleX, scaleY, Matrix2D._TempScalingMatrix);

+ 13 - 12
materialsLibrary/src/background/babylon.backgroundMaterial.ts

@@ -266,7 +266,7 @@ namespace BABYLON {
         /**
         /**
          * Gets the image processing configuration used either in this material.
          * Gets the image processing configuration used either in this material.
          */
          */
-        public get imageProcessingConfiguration(): ImageProcessingConfiguration {
+        public get imageProcessingConfiguration(): Nullable<ImageProcessingConfiguration> {
             return this._imageProcessingConfiguration;
             return this._imageProcessingConfiguration;
         }
         }
 
 
@@ -286,26 +286,26 @@ namespace BABYLON {
          * Gets wether the color curves effect is enabled.
          * Gets wether the color curves effect is enabled.
          */
          */
         public get cameraColorCurvesEnabled(): boolean {
         public get cameraColorCurvesEnabled(): boolean {
-            return this.imageProcessingConfiguration.colorCurvesEnabled;
+            return (<ImageProcessingConfiguration>this.imageProcessingConfiguration).colorCurvesEnabled;
         }
         }
         /**
         /**
          * Sets wether the color curves effect is enabled.
          * Sets wether the color curves effect is enabled.
          */
          */
         public set cameraColorCurvesEnabled(value: boolean) {
         public set cameraColorCurvesEnabled(value: boolean) {
-            this.imageProcessingConfiguration.colorCurvesEnabled = value;
+            (<ImageProcessingConfiguration>this.imageProcessingConfiguration).colorCurvesEnabled = value;
         }
         }
 
 
         /**
         /**
          * Gets wether the color grading effect is enabled.
          * Gets wether the color grading effect is enabled.
          */
          */
         public get cameraColorGradingEnabled(): boolean {
         public get cameraColorGradingEnabled(): boolean {
-            return this.imageProcessingConfiguration.colorGradingEnabled;
+            return (<ImageProcessingConfiguration>this.imageProcessingConfiguration).colorGradingEnabled;
         }
         }
         /**
         /**
          * Gets wether the color grading effect is enabled.
          * Gets wether the color grading effect is enabled.
          */
          */
         public set cameraColorGradingEnabled(value: boolean) {
         public set cameraColorGradingEnabled(value: boolean) {
-            this.imageProcessingConfiguration.colorGradingEnabled = value;
+            (<ImageProcessingConfiguration>this.imageProcessingConfiguration).colorGradingEnabled = value;
         }
         }
 
 
         /**
         /**
@@ -362,7 +362,7 @@ namespace BABYLON {
          * Sets the Color Grading 2D Lookup Texture.
          * Sets the Color Grading 2D Lookup Texture.
          */
          */
         public set cameraColorGradingTexture(value: Nullable<BaseTexture>) {
         public set cameraColorGradingTexture(value: Nullable<BaseTexture>) {
-            this._imageProcessingConfiguration.colorGradingTexture = value;
+            (<ImageProcessingConfiguration>this.imageProcessingConfiguration).colorGradingTexture = value;
         }
         }
 
 
         /**
         /**
@@ -372,7 +372,7 @@ namespace BABYLON {
          * corresponding to low luminance, medium luminance, and high luminance areas respectively.
          * corresponding to low luminance, medium luminance, and high luminance areas respectively.
          */
          */
         public get cameraColorCurves(): Nullable<ColorCurves> {
         public get cameraColorCurves(): Nullable<ColorCurves> {
-            return this._imageProcessingConfiguration.colorCurves;
+            return (<ImageProcessingConfiguration>this.imageProcessingConfiguration).colorCurves;
         }
         }
         /**
         /**
          * The color grading curves provide additional color adjustmnent that is applied after any color grading transform (3D LUT). 
          * The color grading curves provide additional color adjustmnent that is applied after any color grading transform (3D LUT). 
@@ -381,7 +381,7 @@ namespace BABYLON {
          * corresponding to low luminance, medium luminance, and high luminance areas respectively.
          * corresponding to low luminance, medium luminance, and high luminance areas respectively.
          */
          */
         public set cameraColorCurves(value: Nullable<ColorCurves>) {
         public set cameraColorCurves(value: Nullable<ColorCurves>) {
-            this._imageProcessingConfiguration.colorCurves = value;
+            (<ImageProcessingConfiguration>this.imageProcessingConfiguration).colorCurves = value;
         }
         }
 
 
         /**
         /**
@@ -630,7 +630,7 @@ namespace BABYLON {
                 this.buildUniformLayout();
                 this.buildUniformLayout();
             }
             }
 
 
-            if (!subMesh.effect.isReady()) {
+            if (!subMesh.effect || !subMesh.effect.isReady()) {
                 return false;
                 return false;
             }
             }
 
 
@@ -695,6 +695,9 @@ namespace BABYLON {
             }
             }
 
 
             var effect = subMesh.effect;
             var effect = subMesh.effect;
+            if (!effect) {
+                return;
+            }            
             this._activeEffect = effect;
             this._activeEffect = effect;
 
 
             // Matrices
             // Matrices
@@ -767,7 +770,7 @@ namespace BABYLON {
                 // Clip plane
                 // Clip plane
                 MaterialHelper.BindClipPlane(this._activeEffect, scene);
                 MaterialHelper.BindClipPlane(this._activeEffect, scene);
 
 
-                var eyePosition = scene._mirroredCameraPosition ? scene._mirroredCameraPosition : scene.activeCamera.globalPosition;
+                var eyePosition = scene._mirroredCameraPosition ? scene._mirroredCameraPosition : (<Camera>scene.activeCamera).globalPosition;
                 // var invertNormal = (scene.useRightHandedSystem === (scene._mirroredCameraPosition != null));
                 // var invertNormal = (scene.useRightHandedSystem === (scene._mirroredCameraPosition != null));
                 effect.setFloat3("vEyePosition",
                 effect.setFloat3("vEyePosition",
                     eyePosition.x,
                     eyePosition.x,
@@ -793,8 +796,6 @@ namespace BABYLON {
             this._uniformBuffer.update();
             this._uniformBuffer.update();
 
 
             this._afterBind(mesh);
             this._afterBind(mesh);
-
-            scene = null;
         }
         }
 
 
         /**
         /**

+ 7 - 4
materialsLibrary/src/cell/babylon.cellMaterial.ts

@@ -64,7 +64,7 @@ module BABYLON {
             return false;
             return false;
         }
         }
 
 
-        public getAlphaTestTexture(): BaseTexture {
+        public getAlphaTestTexture(): Nullable<BaseTexture> {
             return null;
             return null;
         }
         }
 
 
@@ -116,7 +116,7 @@ module BABYLON {
             defines._needNormals = MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights, this._disableLighting);
             defines._needNormals = MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights, this._disableLighting);
 
 
             // Values that need to be evaluated on every frame
             // Values that need to be evaluated on every frame
-            MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances);
+            MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false);
             
             
             // Attribs
             // Attribs
             MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true);
             MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true);
@@ -192,7 +192,7 @@ module BABYLON {
                     }, engine), defines);
                     }, engine), defines);
 
 
             }
             }
-            if (!subMesh.effect.isReady()) {
+            if (!subMesh.effect || !subMesh.effect.isReady()) {
                 return false;
                 return false;
             }
             }
 
 
@@ -211,6 +211,9 @@ module BABYLON {
             }
             }
 
 
             var effect = subMesh.effect;
             var effect = subMesh.effect;
+            if (!effect) {
+                return;
+            }
             this._activeEffect = effect;
             this._activeEffect = effect;
 
 
             // Matrices        
             // Matrices        
@@ -237,7 +240,7 @@ module BABYLON {
                     this._activeEffect.setFloat("pointSize", this.pointSize);
                     this._activeEffect.setFloat("pointSize", this.pointSize);
                 }
                 }
 
 
-                this._activeEffect.setVector3("vEyePosition", scene._mirroredCameraPosition ? scene._mirroredCameraPosition : scene.activeCamera.position);                
+                this._activeEffect.setVector3("vEyePosition", scene._mirroredCameraPosition ? scene._mirroredCameraPosition : (<Camera>scene.activeCamera).position);                
             }
             }
 
 
             this._activeEffect.setColor4("vDiffuseColor", this.diffuseColor, this.alpha * mesh.visibility);
             this._activeEffect.setColor4("vDiffuseColor", this.diffuseColor, this.alpha * mesh.visibility);

+ 15 - 9
materialsLibrary/src/custom/babylon.customMaterial.ts

@@ -310,13 +310,13 @@ module BABYLON {
         /**
         /**
          * Keep track of the image processing observer to allow dispose and replace.
          * Keep track of the image processing observer to allow dispose and replace.
          */
          */
-        private _imageProcessingObserver: Observer<ImageProcessingConfiguration>;
+        private _imageProcessingObserver: Nullable<Observer<ImageProcessingConfiguration>>;
 
 
         /**
         /**
          * Attaches a new image processing configuration to the Standard Material.
          * Attaches a new image processing configuration to the Standard Material.
          * @param configuration 
          * @param configuration 
          */
          */
-        protected _attachImageProcessingConfiguration(configuration: ImageProcessingConfiguration): void {
+        protected _attachImageProcessingConfiguration(configuration: Nullable<ImageProcessingConfiguration>): void {
             if (configuration === this._imageProcessingConfiguration) {
             if (configuration === this._imageProcessingConfiguration) {
                 return;
                 return;
             }
             }
@@ -413,13 +413,13 @@ module BABYLON {
         /**
         /**
          * Gets the Color Grading 2D Lookup Texture.
          * Gets the Color Grading 2D Lookup Texture.
          */
          */
-        public get cameraColorGradingTexture(): BaseTexture {
+        public get cameraColorGradingTexture(): Nullable<BaseTexture> {
             return this._imageProcessingConfiguration.colorGradingTexture;
             return this._imageProcessingConfiguration.colorGradingTexture;
         }
         }
         /**
         /**
          * Sets the Color Grading 2D Lookup Texture.
          * Sets the Color Grading 2D Lookup Texture.
          */
          */
-        public set cameraColorGradingTexture(value: BaseTexture) {
+        public set cameraColorGradingTexture(value: Nullable<BaseTexture>) {
             this._imageProcessingConfiguration.colorGradingTexture = value;
             this._imageProcessingConfiguration.colorGradingTexture = value;
         }
         }
 
 
@@ -721,7 +721,7 @@ module BABYLON {
             MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true, true);
             MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true, true);
 
 
             // Values that need to be evaluated on every frame
             // Values that need to be evaluated on every frame
-            MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances);
+            MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false);
 
 
             // Get correct effect      
             // Get correct effect      
             if (defines.isDirty) {
             if (defines.isDirty) {
@@ -861,7 +861,7 @@ module BABYLON {
                 this.buildUniformLayout();
                 this.buildUniformLayout();
             }
             }
 
 
-            if (!subMesh.effect.isReady()) {
+            if (!subMesh.effect || !subMesh.effect.isReady()) {
                 return false;
                 return false;
             }
             }
 
 
@@ -934,6 +934,9 @@ module BABYLON {
             }
             }
 
 
             var effect = subMesh.effect;
             var effect = subMesh.effect;
+            if (!effect) {
+                return;
+            }
             this._activeEffect = effect;
             this._activeEffect = effect;
 
 
             // Matrices        
             // Matrices        
@@ -1103,7 +1106,7 @@ module BABYLON {
                 // Colors
                 // Colors
                 scene.ambientColor.multiplyToRef(this.ambientColor, this._globalAmbientColor);
                 scene.ambientColor.multiplyToRef(this.ambientColor, this._globalAmbientColor);
 
 
-                effect.setVector3("vEyePosition", scene._mirroredCameraPosition ? scene._mirroredCameraPosition : scene.activeCamera.position);
+                effect.setVector3("vEyePosition", scene._mirroredCameraPosition ? scene._mirroredCameraPosition : (<Camera>scene.activeCamera).position);
                 effect.setColor3("vAmbientColor", this._globalAmbientColor);
                 effect.setColor3("vAmbientColor", this._globalAmbientColor);
             }
             }
 
 
@@ -2033,7 +2036,7 @@ vColor=color;\n\
               this._isCreatedShader  = false;
               this._isCreatedShader  = false;
             
             
             CustomMaterial.ShaderIndexer++;
             CustomMaterial.ShaderIndexer++;
-            var name: string = name + "custom_" + CustomMaterial.ShaderIndexer;
+            var name: string = "custom_" + CustomMaterial.ShaderIndexer;
 
 
             this.ReviewUniform("uniform",uniforms);
             this.ReviewUniform("uniform",uniforms);
             this.ReviewUniform("sampler",samplers);
             this.ReviewUniform("sampler",samplers);
@@ -2041,7 +2044,10 @@ vColor=color;\n\
 
 
             var fn_afterBind = this._afterBind;
             var fn_afterBind = this._afterBind;
             this._afterBind = (m,e) => { 
             this._afterBind = (m,e) => { 
-                this.AttachAfterBind(m,e);
+                if (!e) {
+                    return;
+                }
+                this.AttachAfterBind(m, e);
                 try{fn_afterBind(m,e);}catch(e){};
                 try{fn_afterBind(m,e);}catch(e){};
             } ;
             } ;
 
 

+ 17 - 12
materialsLibrary/src/fire/babylon.fireMaterial.ts

@@ -24,19 +24,19 @@ module BABYLON {
 
 
     export class FireMaterial extends PushMaterial {
     export class FireMaterial extends PushMaterial {
         @serializeAsTexture("diffuseTexture")
         @serializeAsTexture("diffuseTexture")
-        private _diffuseTexture: BaseTexture;
+        private _diffuseTexture: Nullable<BaseTexture>;
         @expandToProperty("_markAllSubMeshesAsTexturesDirty")
         @expandToProperty("_markAllSubMeshesAsTexturesDirty")
-        public diffuseTexture: BaseTexture;        
+        public diffuseTexture: Nullable<BaseTexture>;        
         
         
         @serializeAsTexture("distortionTexture")
         @serializeAsTexture("distortionTexture")
-        private _distortionTexture: BaseTexture;
+        private _distortionTexture: Nullable<BaseTexture>;
         @expandToProperty("_markAllSubMeshesAsTexturesDirty")
         @expandToProperty("_markAllSubMeshesAsTexturesDirty")
-        public distortionTexture: BaseTexture;       
+        public distortionTexture: Nullable<BaseTexture>;       
         
         
         @serializeAsTexture("opacityTexture")
         @serializeAsTexture("opacityTexture")
-        private _opacityTexture: BaseTexture;
+        private _opacityTexture: Nullable<BaseTexture>;
         @expandToProperty("_markAllSubMeshesAsTexturesDirty")
         @expandToProperty("_markAllSubMeshesAsTexturesDirty")
-        public opacityTexture: BaseTexture;
+        public opacityTexture: Nullable<BaseTexture>;
         
         
         @serialize("diffuseColor")
         @serialize("diffuseColor")
         public diffuseColor = new Color3(1, 1, 1);
         public diffuseColor = new Color3(1, 1, 1);
@@ -60,7 +60,7 @@ module BABYLON {
             return true;
             return true;
         }
         }
 
 
-        public getAlphaTestTexture(): BaseTexture {
+        public getAlphaTestTexture(): Nullable<BaseTexture> {
             return null;
             return null;
         }
         }
 
 
@@ -107,7 +107,7 @@ module BABYLON {
             }
             }
             
             
             // Values that need to be evaluated on every frame
             // Values that need to be evaluated on every frame
-            MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances);
+            MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false);
             
             
             // Attribs
             // Attribs
             MaterialHelper.PrepareDefinesForAttributes(mesh, defines, false, true);
             MaterialHelper.PrepareDefinesForAttributes(mesh, defines, false, true);
@@ -147,7 +147,7 @@ module BABYLON {
                 
                 
                 var join = defines.toString();
                 var join = defines.toString();
                 subMesh.setEffect(scene.getEngine().createEffect(shaderName,
                 subMesh.setEffect(scene.getEngine().createEffect(shaderName,
-                    <EffectCreationOptions>{
+                    {
                         attributes: attribs,
                         attributes: attribs,
                         uniformsNames: ["world", "view", "viewProjection", "vEyePosition",
                         uniformsNames: ["world", "view", "viewProjection", "vEyePosition",
                                 "vFogInfos", "vFogColor", "pointSize",
                                 "vFogInfos", "vFogColor", "pointSize",
@@ -165,11 +165,13 @@ module BABYLON {
                         defines: join,
                         defines: join,
                         fallbacks: fallbacks,
                         fallbacks: fallbacks,
                         onCompiled: this.onCompiled,
                         onCompiled: this.onCompiled,
-                        onError: this.onError
+                        onError: this.onError,
+                        indexParameters: null,
+                        maxSimultaneousLights: 4
                     }, engine), defines);
                     }, engine), defines);
             }
             }
             
             
-            if (!subMesh.effect.isReady()) {
+            if (!subMesh.effect || !subMesh.effect.isReady()) {
                 return false;
                 return false;
             }
             }
 
 
@@ -188,6 +190,9 @@ module BABYLON {
             }
             }
 
 
             var effect = subMesh.effect;
             var effect = subMesh.effect;
+            if (!effect) {
+                return;
+            }
             this._activeEffect = effect;
             this._activeEffect = effect;
 
 
             // Matrices
             // Matrices
@@ -220,7 +225,7 @@ module BABYLON {
                     this._activeEffect.setFloat("pointSize", this.pointSize);
                     this._activeEffect.setFloat("pointSize", this.pointSize);
                 }
                 }
 
 
-                this._activeEffect.setVector3("vEyePosition", scene._mirroredCameraPosition ? scene._mirroredCameraPosition : scene.activeCamera.position);                
+                this._activeEffect.setVector3("vEyePosition", scene._mirroredCameraPosition ? scene._mirroredCameraPosition : (<Camera>scene.activeCamera).position);                
             }
             }
 
 
             this._activeEffect.setColor4("vDiffuseColor", this._scaledDiffuse, this.alpha * mesh.visibility);
             this._activeEffect.setColor4("vDiffuseColor", this._scaledDiffuse, this.alpha * mesh.visibility);

+ 12 - 5
materialsLibrary/src/fur/babylon.furMaterial.ts

@@ -107,7 +107,7 @@ module BABYLON {
             return false;
             return false;
         }
         }
 
 
-        public getAlphaTestTexture(): BaseTexture {
+        public getAlphaTestTexture(): Nullable<BaseTexture> {
             return null;
             return null;
         }
         }
         
         
@@ -187,7 +187,7 @@ module BABYLON {
             defines._needNormals = MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights, this._disableLighting);
             defines._needNormals = MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights, this._disableLighting);
 
 
             // Values that need to be evaluated on every frame
             // Values that need to be evaluated on every frame
-            MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances);
+            MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false);
             
             
             // Attribs
             // Attribs
             MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true);
             MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true);
@@ -269,7 +269,7 @@ module BABYLON {
                         indexParameters: { maxSimultaneousLights: this.maxSimultaneousLights }
                         indexParameters: { maxSimultaneousLights: this.maxSimultaneousLights }
                     }, engine), defines);
                     }, engine), defines);
             }
             }
-            if (!subMesh.effect.isReady()) {
+            if (!subMesh.effect || !subMesh.effect.isReady()) {
                 return false;
                 return false;
             }
             }
 
 
@@ -288,6 +288,9 @@ module BABYLON {
             }
             }
 
 
             var effect = subMesh.effect;
             var effect = subMesh.effect;
+            if (!effect) {
+                return;
+            }
             this._activeEffect = effect;
             this._activeEffect = effect;
 
 
             // Matrices        
             // Matrices        
@@ -318,7 +321,7 @@ module BABYLON {
                     this._activeEffect.setFloat("pointSize", this.pointSize);
                     this._activeEffect.setFloat("pointSize", this.pointSize);
                 }
                 }
 
 
-                this._activeEffect.setVector3("vEyePosition", scene._mirroredCameraPosition ? scene._mirroredCameraPosition : scene.activeCamera.position);                
+                this._activeEffect.setVector3("vEyePosition", scene._mirroredCameraPosition ? scene._mirroredCameraPosition : (<Camera>scene.activeCamera).position);                
             }
             }
 
 
             this._activeEffect.setColor4("vDiffuseColor", this.diffuseColor, this.alpha * mesh.visibility);
             this._activeEffect.setColor4("vDiffuseColor", this.diffuseColor, this.alpha * mesh.visibility);
@@ -405,7 +408,11 @@ module BABYLON {
             
             
             if (this._meshes) {
             if (this._meshes) {
                 for (var i = 1; i < this._meshes.length; i++) {
                 for (var i = 1; i < this._meshes.length; i++) {
-                    this._meshes[i].material.dispose(forceDisposeEffect);
+                    let mat = this._meshes[i].material;
+
+                    if (mat) {
+                        mat.dispose(forceDisposeEffect);
+                    }
                     this._meshes[i].dispose();
                     this._meshes[i].dispose();
                 }
                 }
             }
             }

+ 10 - 6
materialsLibrary/src/gradient/babylon.gradientMaterial.ts

@@ -101,7 +101,7 @@ module BABYLON {
             return true;
             return true;
         }
         }
 
 
-        public getAlphaTestTexture(): BaseTexture {
+        public getAlphaTestTexture(): Nullable<BaseTexture> {
             return null;
             return null;
         }
         }
 
 
@@ -128,7 +128,7 @@ module BABYLON {
 
 
             var engine = scene.getEngine();
             var engine = scene.getEngine();
 
 
-            MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances);
+            MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false);
 
 
             MaterialHelper.PrepareDefinesForMisc(mesh, scene, false, this.pointsCloud, this.fogEnabled, defines);
             MaterialHelper.PrepareDefinesForMisc(mesh, scene, false, this.pointsCloud, this.fogEnabled, defines);
 
 
@@ -213,7 +213,7 @@ module BABYLON {
                         indexParameters: { maxSimultaneousLights: 4 }
                         indexParameters: { maxSimultaneousLights: 4 }
                     }, engine), defines);
                     }, engine), defines);
             }
             }
-            if (!subMesh.effect.isReady()) {
+            if (!subMesh.effect || !subMesh.effect.isReady()) {
                 return false;
                 return false;
             }
             }
 
 
@@ -232,6 +232,10 @@ module BABYLON {
             }
             }
 
 
             var effect = subMesh.effect;
             var effect = subMesh.effect;
+            if (!effect) {
+                return;
+            }
+
             this._activeEffect = effect;
             this._activeEffect = effect;
             
             
             // Matrices        
             // Matrices        
@@ -239,18 +243,18 @@ module BABYLON {
             this._activeEffect.setMatrix("viewProjection", scene.getTransformMatrix());
             this._activeEffect.setMatrix("viewProjection", scene.getTransformMatrix());
 
 
             // Bones
             // Bones
-            MaterialHelper.BindBonesParameters(mesh, this._effect);
+            MaterialHelper.BindBonesParameters(mesh, effect);
 
 
             if (this._mustRebind(scene, effect)) {
             if (this._mustRebind(scene, effect)) {
                 // Clip plane
                 // Clip plane
-                MaterialHelper.BindClipPlane(this._effect, scene);
+                MaterialHelper.BindClipPlane(effect, scene);
 
 
                 // Point size
                 // Point size
                 if (this.pointsCloud) {
                 if (this.pointsCloud) {
                     this._activeEffect.setFloat("pointSize", this.pointSize);
                     this._activeEffect.setFloat("pointSize", this.pointSize);
                 }
                 }
 
 
-                this._activeEffect.setVector3("vEyePosition", scene._mirroredCameraPosition ? scene._mirroredCameraPosition : scene.activeCamera.position);                
+                this._activeEffect.setVector3("vEyePosition", scene._mirroredCameraPosition ? scene._mirroredCameraPosition : (<Camera>scene.activeCamera).position);                
             }
             }
 
 
             this._activeEffect.setColor4("vDiffuseColor", this._scaledDiffuse, this.alpha * mesh.visibility);
             this._activeEffect.setColor4("vDiffuseColor", this._scaledDiffuse, this.alpha * mesh.visibility);

+ 5 - 2
materialsLibrary/src/grid/babylon.gridmaterial.ts

@@ -133,12 +133,12 @@ module BABYLON {
                     ["projection", "worldView", "mainColor", "lineColor", "gridControl", "gridOffset", "vFogInfos", "vFogColor", "world", "view"],
                     ["projection", "worldView", "mainColor", "lineColor", "gridControl", "gridOffset", "vFogInfos", "vFogColor", "world", "view"],
                     [],
                     [],
                     join,
                     join,
-                    null,
+                    undefined,
                     this.onCompiled,
                     this.onCompiled,
                     this.onError), defines);
                     this.onError), defines);
             }
             }
 
 
-            if (!subMesh.effect.isReady()) {
+            if (!subMesh.effect || !subMesh.effect.isReady()) {
                 return false;
                 return false;
             }
             }
 
 
@@ -157,6 +157,9 @@ module BABYLON {
             }
             }
 
 
             var effect = subMesh.effect;
             var effect = subMesh.effect;
+            if (!effect) {
+                return;
+            }
             this._activeEffect = effect;
             this._activeEffect = effect;
 
 
             // Matrices
             // Matrices

+ 8 - 4
materialsLibrary/src/lava/babylon.lavaMaterial.ts

@@ -110,7 +110,7 @@ module BABYLON {
             return false;
             return false;
         }
         }
 
 
-        public getAlphaTestTexture(): BaseTexture {
+        public getAlphaTestTexture(): Nullable<BaseTexture> {
             return null;
             return null;
         }
         }
 
 
@@ -159,7 +159,7 @@ module BABYLON {
             defines._needNormals = MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights, this._disableLighting);
             defines._needNormals = MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights, this._disableLighting);
 
 
             // Values that need to be evaluated on every frame
             // Values that need to be evaluated on every frame
-            MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances);
+            MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false);
             
             
             // Attribs
             // Attribs
             MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true);
             MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true);
@@ -242,7 +242,7 @@ module BABYLON {
                         indexParameters: { maxSimultaneousLights: this.maxSimultaneousLights }
                         indexParameters: { maxSimultaneousLights: this.maxSimultaneousLights }
                     }, engine), defines);
                     }, engine), defines);
             }
             }
-            if (!subMesh.effect.isReady()) {
+            if (!subMesh.effect || !subMesh.effect.isReady()) {
                 return false;
                 return false;
             }
             }
 
 
@@ -261,6 +261,10 @@ module BABYLON {
             }
             }
 
 
             var effect = subMesh.effect;
             var effect = subMesh.effect;
+
+            if (!effect) {
+                return;
+            }
             this._activeEffect = effect;
             this._activeEffect = effect;
 
 
             // Matrices        
             // Matrices        
@@ -291,7 +295,7 @@ module BABYLON {
                     this._activeEffect.setFloat("pointSize", this.pointSize);
                     this._activeEffect.setFloat("pointSize", this.pointSize);
                 }
                 }
 
 
-                this._activeEffect.setVector3("vEyePosition", scene._mirroredCameraPosition ? scene._mirroredCameraPosition : scene.activeCamera.position);
+                this._activeEffect.setVector3("vEyePosition", scene._mirroredCameraPosition ? scene._mirroredCameraPosition : (<Camera>scene.activeCamera).position);
             }
             }
 
 
             this._activeEffect.setColor4("vDiffuseColor", this._scaledDiffuse, this.alpha * mesh.visibility);
             this._activeEffect.setColor4("vDiffuseColor", this._scaledDiffuse, this.alpha * mesh.visibility);

+ 55 - 41
materialsLibrary/src/legacyPBR/babylon.legacyPBRMaterial.ts

@@ -169,7 +169,7 @@ module BABYLON {
          * This allows special effects like sepia, black and white to sixties rendering style. 
          * This allows special effects like sepia, black and white to sixties rendering style. 
          */
          */
         @serializeAsTexture()
         @serializeAsTexture()
-        public cameraColorGradingTexture: BaseTexture = null;
+        public cameraColorGradingTexture: Nullable<BaseTexture> = null;
         
         
         /**
         /**
          * The color grading curves provide additional color adjustmnent that is applied after any color grading transform (3D LUT). 
          * The color grading curves provide additional color adjustmnent that is applied after any color grading transform (3D LUT). 
@@ -178,7 +178,7 @@ module BABYLON {
          * corresponding to low luminance, medium luminance, and high luminance areas respectively.
          * corresponding to low luminance, medium luminance, and high luminance areas respectively.
          */
          */
         @serializeAsColorCurves()
         @serializeAsColorCurves()
-        public cameraColorCurves: ColorCurves = null;
+        public cameraColorCurves: Nullable<ColorCurves> = null;
          
          
         private _cameraInfos: Vector4 = new Vector4(1.0, 1.0, 0.0, 0.0);
         private _cameraInfos: Vector4 = new Vector4(1.0, 1.0, 0.0, 0.0);
 
 
@@ -666,7 +666,7 @@ module BABYLON {
             }
             }
         }
         }
 
 
-        public isReady(mesh?: AbstractMesh, useInstances?: boolean): boolean {
+        public isReady(mesh: Nullable<AbstractMesh> = null, useInstances?: boolean): boolean {
             if (this.isFrozen) {
             if (this.isFrozen) {
                 if (this._wasPreviouslyReady) {
                 if (this._wasPreviouslyReady) {
                     return true;
                     return true;
@@ -679,11 +679,11 @@ module BABYLON {
 
 
             this._defines.reset();
             this._defines.reset();
 
 
-            if (scene.lightsEnabled && !this.disableLighting) {
+            if (scene.lightsEnabled && !this.disableLighting && mesh) {
                 MaterialHelper.PrepareDefinesForLights(scene, mesh, this._defines, true, this.maxSimultaneousLights);
                 MaterialHelper.PrepareDefinesForLights(scene, mesh, this._defines, true, this.maxSimultaneousLights);
             }
             }
 
 
-            if (!this.checkReadyOnEveryCall) {
+            if (!this.checkReadyOnEveryCall && mesh) {
                 if (this._renderId === scene.getRenderId()) {
                 if (this._renderId === scene.getRenderId()) {
                     if (this._checkCache(scene, mesh, useInstances)) {
                     if (this._checkCache(scene, mesh, useInstances)) {
                         return true;
                         return true;
@@ -1009,7 +1009,7 @@ module BABYLON {
                 }
                 }
                 if (mesh.useBones && mesh.computeBonesUsingShaders) {
                 if (mesh.useBones && mesh.computeBonesUsingShaders) {
                     this._defines.NUM_BONE_INFLUENCERS = mesh.numBoneInfluencers;
                     this._defines.NUM_BONE_INFLUENCERS = mesh.numBoneInfluencers;
-                    this._defines.BonesPerMesh = (mesh.skeleton.bones.length + 1);
+                    this._defines.BonesPerMesh = (mesh.skeleton ? mesh.skeleton.bones.length + 1 : 0);
                 }
                 }
 
 
                 // Instances
                 // Instances
@@ -1017,8 +1017,8 @@ module BABYLON {
                     this._defines.INSTANCES = true;
                     this._defines.INSTANCES = true;
                 }
                 }
 
 
-               if ((<any>mesh).morphTargetManager) {
-                    var manager = (<Mesh>mesh).morphTargetManager;
+                let manager = (<any>mesh).morphTargetManager;
+                if (manager) {
                     this._defines.MORPHTARGETS_TANGENT = manager.supportsTangents && this._defines.TANGENT;
                     this._defines.MORPHTARGETS_TANGENT = manager.supportsTangents && this._defines.TANGENT;
                     this._defines.MORPHTARGETS_NORMAL = manager.supportsNormals && this._defines.NORMAL;
                     this._defines.MORPHTARGETS_NORMAL = manager.supportsNormals && this._defines.NORMAL;
                     this._defines.MORPHTARGETS = (manager.numInfluencers > 0);
                     this._defines.MORPHTARGETS = (manager.numInfluencers > 0);
@@ -1093,7 +1093,7 @@ module BABYLON {
                 }
                 }
 
 
                 if (this._defines.NUM_BONE_INFLUENCERS > 0) {
                 if (this._defines.NUM_BONE_INFLUENCERS > 0) {
-                    fallbacks.addCPUSkinningFallback(0, mesh);
+                    fallbacks.addCPUSkinningFallback(0, <Mesh>mesh);
                 }
                 }
 
 
                 //Attributes
                 //Attributes
@@ -1119,9 +1119,11 @@ module BABYLON {
                     attribs.push(VertexBuffer.ColorKind);
                     attribs.push(VertexBuffer.ColorKind);
                 }
                 }
 
 
-                MaterialHelper.PrepareAttributesForBones(attribs, mesh, this._defines, fallbacks);
-                MaterialHelper.PrepareAttributesForInstances(attribs, this._defines);
-                MaterialHelper.PrepareAttributesForMorphTargets(attribs, mesh, this._defines);
+                if (mesh) {
+                    MaterialHelper.PrepareAttributesForBones(attribs, mesh, this._defines, fallbacks);
+                    MaterialHelper.PrepareAttributesForInstances(attribs, this._defines);
+                    MaterialHelper.PrepareAttributesForMorphTargets(attribs, mesh, this._defines);
+                }
 
 
                 // Legacy browser patch
                 // Legacy browser patch
                 var join = this._defines.toString();
                 var join = this._defines.toString();
@@ -1187,7 +1189,7 @@ module BABYLON {
                 
                 
                 this.buildUniformLayout();
                 this.buildUniformLayout();
             }
             }
-            if (!this._effect.isReady()) {
+            if (!this._effect || !this._effect.isReady()) {
                 return false;
                 return false;
             }
             }
 
 
@@ -1259,19 +1261,26 @@ module BABYLON {
         }
         }
 
 
         public bindOnlyWorldMatrix(world: Matrix): void {
         public bindOnlyWorldMatrix(world: Matrix): void {
-            this._effect.setMatrix("world", world);
+            if (this._effect) {
+                this._effect.setMatrix("world", world);
+            }
         }
         }
 
 
-        private _myScene: BABYLON.Scene = null;
+        private _myScene: Nullable<BABYLON.Scene> = null;
 
 
         public bind(world: Matrix, mesh?: Mesh): void {
         public bind(world: Matrix, mesh?: Mesh): void {
             this._myScene = this.getScene();
             this._myScene = this.getScene();
             var effect = this._effect;
             var effect = this._effect;
+
+            if (!effect) {
+                return;
+            }
+
             // Matrices        
             // Matrices        
             this.bindOnlyWorldMatrix(world);
             this.bindOnlyWorldMatrix(world);
 
 
             // Bones
             // Bones
-            MaterialHelper.BindBonesParameters(mesh, this._effect);
+            MaterialHelper.BindBonesParameters(mesh, effect);
 
 
             if (this._myScene.getCachedMaterial() !== (<BABYLON.Material>this)) {
             if (this._myScene.getCachedMaterial() !== (<BABYLON.Material>this)) {
                 this._uniformBuffer.bindToEffect(effect, "Material");
                 this._uniformBuffer.bindToEffect(effect, "Material");
@@ -1316,19 +1325,22 @@ module BABYLON {
 
 
                             if (this._defines.USESPHERICALFROMREFLECTIONMAP) {
                             if (this._defines.USESPHERICALFROMREFLECTIONMAP) {
                                 var polynomials = this.reflectionTexture.sphericalPolynomial;
                                 var polynomials = this.reflectionTexture.sphericalPolynomial;
-                                this._effect.setFloat3("vSphericalX", polynomials.x.x, polynomials.x.y, polynomials.x.z);
-                                this._effect.setFloat3("vSphericalY", polynomials.y.x, polynomials.y.y, polynomials.y.z);
-                                this._effect.setFloat3("vSphericalZ", polynomials.z.x, polynomials.z.y, polynomials.z.z);
-                                this._effect.setFloat3("vSphericalXX_ZZ", polynomials.xx.x - polynomials.zz.x,
-                                    polynomials.xx.y - polynomials.zz.y,
-                                    polynomials.xx.z - polynomials.zz.z);
-                                this._effect.setFloat3("vSphericalYY_ZZ", polynomials.yy.x - polynomials.zz.x,
-                                    polynomials.yy.y - polynomials.zz.y,
-                                    polynomials.yy.z - polynomials.zz.z);
-                                this._effect.setFloat3("vSphericalZZ", polynomials.zz.x, polynomials.zz.y, polynomials.zz.z);
-                                this._effect.setFloat3("vSphericalXY", polynomials.xy.x, polynomials.xy.y, polynomials.xy.z);
-                                this._effect.setFloat3("vSphericalYZ", polynomials.yz.x, polynomials.yz.y, polynomials.yz.z);
-                                this._effect.setFloat3("vSphericalZX", polynomials.zx.x, polynomials.zx.y, polynomials.zx.z);
+
+                                if (polynomials) {
+                                    effect.setFloat3("vSphericalX", polynomials.x.x, polynomials.x.y, polynomials.x.z);
+                                    effect.setFloat3("vSphericalY", polynomials.y.x, polynomials.y.y, polynomials.y.z);
+                                    effect.setFloat3("vSphericalZ", polynomials.z.x, polynomials.z.y, polynomials.z.z);
+                                    effect.setFloat3("vSphericalXX_ZZ", polynomials.xx.x - polynomials.zz.x,
+                                        polynomials.xx.y - polynomials.zz.y,
+                                        polynomials.xx.z - polynomials.zz.z);
+                                    effect.setFloat3("vSphericalYY_ZZ", polynomials.yy.x - polynomials.zz.x,
+                                        polynomials.yy.y - polynomials.zz.y,
+                                        polynomials.yy.z - polynomials.zz.z);
+                                    effect.setFloat3("vSphericalZZ", polynomials.zz.x, polynomials.zz.y, polynomials.zz.z);
+                                    effect.setFloat3("vSphericalXY", polynomials.xy.x, polynomials.xy.y, polynomials.xy.z);
+                                    effect.setFloat3("vSphericalYZ", polynomials.yz.x, polynomials.yz.y, polynomials.yz.z);
+                                    effect.setFloat3("vSphericalZX", polynomials.zx.x, polynomials.zx.y, polynomials.zx.z);
+                                }
                             }
                             }
                         }
                         }
 
 
@@ -1415,7 +1427,9 @@ module BABYLON {
 
 
                     // GAMMA CORRECTION.
                     // GAMMA CORRECTION.
                     this.convertColorToLinearSpaceToRef(this.albedoColor, LegacyPBRMaterial._scaledAlbedo);
                     this.convertColorToLinearSpaceToRef(this.albedoColor, LegacyPBRMaterial._scaledAlbedo);
-                    this._uniformBuffer.updateColor4("vAlbedoColor", LegacyPBRMaterial._scaledAlbedo, this.alpha * mesh.visibility);
+                    if (mesh) {
+                        this._uniformBuffer.updateColor4("vAlbedoColor", LegacyPBRMaterial._scaledAlbedo, this.alpha * mesh.visibility);
+                    }
 
 
 
 
                     // Misc
                     // Misc
@@ -1511,14 +1525,14 @@ module BABYLON {
                     }
                     }
 
 
                     if (this.cameraColorGradingTexture && StandardMaterial.ColorGradingTextureEnabled) {
                     if (this.cameraColorGradingTexture && StandardMaterial.ColorGradingTextureEnabled) {
-                        this._effect.setTexture("cameraColorGrading2DSampler", this.cameraColorGradingTexture);
+                        effect.setTexture("cameraColorGrading2DSampler", this.cameraColorGradingTexture);
 
 
                         let x = this.cameraColorGradingTexture.level;                 // Texture Level
                         let x = this.cameraColorGradingTexture.level;                 // Texture Level
                         let y = this.cameraColorGradingTexture.getSize().height;      // Texture Size example with 8
                         let y = this.cameraColorGradingTexture.getSize().height;      // Texture Size example with 8
                         let z = y - 1.0;                    // SizeMinusOne 8 - 1
                         let z = y - 1.0;                    // SizeMinusOne 8 - 1
                         let w = 1 / y;                      // Space of 1 slice 1 / 8
                         let w = 1 / y;                      // Space of 1 slice 1 / 8
                         
                         
-                        this._effect.setFloat4("vCameraColorGradingInfos", x, y, z, w);
+                        effect.setFloat4("vCameraColorGradingInfos", x, y, z, w);
                         
                         
                         let slicePixelSizeU = w / y;    // Space of 1 pixel in U direction, e.g. 1/64
                         let slicePixelSizeU = w / y;    // Space of 1 pixel in U direction, e.g. 1/64
                         let slicePixelSizeV = w;		// Space of 1 pixel in V direction, e.g. 1/8					    // Space of 1 pixel in V direction, e.g. 1/8
                         let slicePixelSizeV = w;		// Space of 1 pixel in V direction, e.g. 1/8					    // Space of 1 pixel in V direction, e.g. 1/8
@@ -1528,25 +1542,25 @@ module BABYLON {
                         let z2 = 0.5 * slicePixelSizeU;	// Offset of lookup range in U to align sample position with texel centre, for example 0.5/64 
                         let z2 = 0.5 * slicePixelSizeU;	// Offset of lookup range in U to align sample position with texel centre, for example 0.5/64 
                         let w2 = 0.5 * slicePixelSizeV;	// Offset of lookup range in V to align sample position with texel centre, for example 0.5/8
                         let w2 = 0.5 * slicePixelSizeV;	// Offset of lookup range in V to align sample position with texel centre, for example 0.5/8
                         
                         
-                        this._effect.setFloat4("vCameraColorGradingScaleOffset", x2, y2, z2, w2);
+                        effect.setFloat4("vCameraColorGradingScaleOffset", x2, y2, z2, w2);
                     }
                     }
                 }
                 }
 
 
                 // Clip plane
                 // Clip plane
-                MaterialHelper.BindClipPlane(this._effect, this._myScene);
+                MaterialHelper.BindClipPlane(effect, this._myScene);
 
 
                 // Colors
                 // Colors
                 this._myScene.ambientColor.multiplyToRef(this.ambientColor, this._globalAmbientColor);
                 this._myScene.ambientColor.multiplyToRef(this.ambientColor, this._globalAmbientColor);
 
 
-                effect.setVector3("vEyePosition", this._myScene._mirroredCameraPosition ? this._myScene._mirroredCameraPosition : this._myScene.activeCamera.position);
+                effect.setVector3("vEyePosition", this._myScene._mirroredCameraPosition ? this._myScene._mirroredCameraPosition : (<Camera>this._myScene.activeCamera).position);
                 effect.setColor3("vAmbientColor", this._globalAmbientColor);
                 effect.setColor3("vAmbientColor", this._globalAmbientColor);
             }
             }
 
 
-            if (this._myScene.getCachedMaterial() !== this || !this.isFrozen) {
+            if (mesh && (this._myScene.getCachedMaterial() !== this || !this.isFrozen)) {
 
 
                 // Lights
                 // Lights
                 if (this._myScene.lightsEnabled && !this.disableLighting) {
                 if (this._myScene.lightsEnabled && !this.disableLighting) {
-                    LegacyPBRMaterial.BindLights(this._myScene, mesh, this._effect, this._defines, this.useScalarInLinearSpace, this.maxSimultaneousLights, this.usePhysicalLightFalloff);
+                    LegacyPBRMaterial.BindLights(this._myScene, mesh, effect, this._defines, this.useScalarInLinearSpace, this.maxSimultaneousLights, this.usePhysicalLightFalloff);
                 }
                 }
 
 
                 // View
                 // View
@@ -1555,11 +1569,11 @@ module BABYLON {
                 }
                 }
 
 
                 // Fog
                 // Fog
-                MaterialHelper.BindFogParameters(this._myScene, mesh, this._effect);
+                MaterialHelper.BindFogParameters(this._myScene, mesh, effect);
 
 
                 // Morph targets
                 // Morph targets
                 if (this._defines.NUM_MORPH_INFLUENCERS) {
                 if (this._defines.NUM_MORPH_INFLUENCERS) {
-                    MaterialHelper.BindMorphTargetParameters(mesh, this._effect);                
+                    MaterialHelper.BindMorphTargetParameters(mesh, effect);                
                 }
                 }
 
 
                 this._cameraInfos.x = this.cameraExposure;
                 this._cameraInfos.x = this.cameraExposure;
@@ -1567,11 +1581,11 @@ module BABYLON {
                 effect.setVector4("vCameraInfos", this._cameraInfos);
                 effect.setVector4("vCameraInfos", this._cameraInfos);
                 
                 
                 if (this.cameraColorCurves) {
                 if (this.cameraColorCurves) {
-                    ColorCurves.Bind(this.cameraColorCurves, this._effect);
+                    ColorCurves.Bind(this.cameraColorCurves, effect);
                 }
                 }
 
 
                 // Log. depth
                 // Log. depth
-                MaterialHelper.BindLogDepth(this._defines, this._effect, this._myScene);
+                MaterialHelper.BindLogDepth(this._defines, effect, this._myScene);
             }
             }
 
 
             this._uniformBuffer.update();
             this._uniformBuffer.update();

+ 7 - 4
materialsLibrary/src/normal/babylon.normalMaterial.ts

@@ -89,7 +89,7 @@ module BABYLON {
             return false;
             return false;
         }
         }
 
 
-        public getAlphaTestTexture(): BaseTexture {
+        public getAlphaTestTexture(): Nullable<BaseTexture> {
             return null;
             return null;
         }
         }
 
 
@@ -138,7 +138,7 @@ module BABYLON {
             defines._needNormals = MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights, this._disableLighting);
             defines._needNormals = MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights, this._disableLighting);
 
 
             // Values that need to be evaluated on every frame
             // Values that need to be evaluated on every frame
-            MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances);
+            MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false);
             
             
             // Attribs
             // Attribs
             MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true);
             MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true);
@@ -216,7 +216,7 @@ module BABYLON {
                         indexParameters: { maxSimultaneousLights: 4 }
                         indexParameters: { maxSimultaneousLights: 4 }
                     }, engine), defines);
                     }, engine), defines);
             }
             }
-            if (!subMesh.effect.isReady()) {
+            if (!subMesh.effect || !subMesh.effect.isReady()) {
                 return false;
                 return false;
             }
             }
 
 
@@ -235,6 +235,9 @@ module BABYLON {
             }
             }
 
 
             var effect = subMesh.effect;
             var effect = subMesh.effect;
+            if (!effect) {
+                return;
+            }
             this._activeEffect = effect;
             this._activeEffect = effect;
 
 
             // Matrices        
             // Matrices        
@@ -260,7 +263,7 @@ module BABYLON {
                     this._activeEffect.setFloat("pointSize", this.pointSize);
                     this._activeEffect.setFloat("pointSize", this.pointSize);
                 }
                 }
 
 
-                this._activeEffect.setVector3("vEyePosition", scene._mirroredCameraPosition ? scene._mirroredCameraPosition : scene.activeCamera.position);                
+                this._activeEffect.setVector3("vEyePosition", scene._mirroredCameraPosition ? scene._mirroredCameraPosition : (<Camera>scene.activeCamera).position);                
             }
             }
 
 
             this._activeEffect.setColor4("vDiffuseColor", this.diffuseColor, this.alpha * mesh.visibility);
             this._activeEffect.setColor4("vDiffuseColor", this.diffuseColor, this.alpha * mesh.visibility);

+ 7 - 4
materialsLibrary/src/shadowOnly/babylon.shadowOnlyMaterial.ts

@@ -32,7 +32,7 @@ module BABYLON {
             return false;
             return false;
         }
         }
 
 
-        public getAlphaTestTexture(): BaseTexture {
+        public getAlphaTestTexture(): Nullable<BaseTexture> {
             return null;
             return null;
         }
         }
 
 
@@ -86,7 +86,7 @@ module BABYLON {
                 }
                 }
             }
             }
 
 
-            MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances);
+            MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false);
 
 
             MaterialHelper.PrepareDefinesForMisc(mesh, scene, false, this.pointsCloud, this.fogEnabled, defines);
             MaterialHelper.PrepareDefinesForMisc(mesh, scene, false, this.pointsCloud, this.fogEnabled, defines);
 
 
@@ -155,7 +155,7 @@ module BABYLON {
                         indexParameters: { maxSimultaneousLights: 1 }
                         indexParameters: { maxSimultaneousLights: 1 }
                     }, engine), defines);
                     }, engine), defines);
             }
             }
-            if (!subMesh.effect.isReady()) {
+            if (!subMesh.effect || !subMesh.effect.isReady()) {
                 return false;
                 return false;
             }
             }
 
 
@@ -174,6 +174,9 @@ module BABYLON {
             }
             }
 
 
             var effect = subMesh.effect;
             var effect = subMesh.effect;
+            if (!effect) {
+                return;
+            }
             this._activeEffect = effect;
             this._activeEffect = effect;
 
 
             // Matrices        
             // Matrices        
@@ -194,7 +197,7 @@ module BABYLON {
 
 
                 this._activeEffect.setFloat("alpha", this.alpha);
                 this._activeEffect.setFloat("alpha", this.alpha);
 
 
-                this._activeEffect.setVector3("vEyePosition", scene._mirroredCameraPosition ? scene._mirroredCameraPosition : scene.activeCamera.position);                
+                this._activeEffect.setVector3("vEyePosition", scene._mirroredCameraPosition ? scene._mirroredCameraPosition : (<Camera>scene.activeCamera).position);                
             }
             }
 
 
             // Lights
             // Lights

+ 7 - 4
materialsLibrary/src/simple/babylon.simpleMaterial.ts

@@ -56,7 +56,7 @@ module BABYLON {
             return false;
             return false;
         }
         }
 
 
-        public getAlphaTestTexture(): BaseTexture {
+        public getAlphaTestTexture(): Nullable<BaseTexture> {
             return null;
             return null;
         }
         }
 
 
@@ -105,7 +105,7 @@ module BABYLON {
             defines._needNormals = MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights, this._disableLighting);
             defines._needNormals = MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights, this._disableLighting);
 
 
             // Values that need to be evaluated on every frame
             // Values that need to be evaluated on every frame
-            MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances);
+            MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false);
             
             
             // Attribs
             // Attribs
             MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true);
             MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true);
@@ -181,7 +181,7 @@ module BABYLON {
                     }, engine), defines);
                     }, engine), defines);
 
 
             }
             }
-            if (!subMesh.effect.isReady()) {
+            if (!subMesh.effect || !subMesh.effect.isReady()) {
                 return false;
                 return false;
             }
             }
 
 
@@ -200,6 +200,9 @@ module BABYLON {
             }
             }
 
 
             var effect = subMesh.effect;
             var effect = subMesh.effect;
+            if (!effect) {
+                return;
+            }
             this._activeEffect = effect;
             this._activeEffect = effect;
 
 
             // Matrices        
             // Matrices        
@@ -226,7 +229,7 @@ module BABYLON {
                     this._activeEffect.setFloat("pointSize", this.pointSize);
                     this._activeEffect.setFloat("pointSize", this.pointSize);
                 }
                 }
 
 
-                this._activeEffect.setVector3("vEyePosition", scene._mirroredCameraPosition ? scene._mirroredCameraPosition : scene.activeCamera.position);                
+                this._activeEffect.setVector3("vEyePosition", scene._mirroredCameraPosition ? scene._mirroredCameraPosition : (<Camera>scene.activeCamera).position);                
             }
             }
 
 
             this._activeEffect.setColor4("vDiffuseColor", this.diffuseColor, this.alpha * mesh.visibility);
             this._activeEffect.setColor4("vDiffuseColor", this.diffuseColor, this.alpha * mesh.visibility);

+ 5 - 2
materialsLibrary/src/sky/babylon.skyMaterial.ts

@@ -63,7 +63,7 @@ module BABYLON {
             return false;
             return false;
         }
         }
 
 
-        public getAlphaTestTexture(): BaseTexture {
+        public getAlphaTestTexture(): Nullable<BaseTexture> {
             return null;
             return null;
         }
         }
 
 
@@ -126,7 +126,7 @@ module BABYLON {
                     join, fallbacks, this.onCompiled, this.onError), defines);
                     join, fallbacks, this.onCompiled, this.onError), defines);
             }
             }
             
             
-            if (!subMesh.effect.isReady()) {
+            if (!subMesh.effect || !subMesh.effect.isReady()) {
                 return false;
                 return false;
             }
             }
 
 
@@ -145,6 +145,9 @@ module BABYLON {
             }
             }
 
 
             var effect = subMesh.effect;
             var effect = subMesh.effect;
+            if (!effect) {
+                return;
+            }
             this._activeEffect = effect;
             this._activeEffect = effect;
 
 
             // Matrices        
             // Matrices        

+ 7 - 4
materialsLibrary/src/terrain/babylon.terrainMaterial.ts

@@ -95,7 +95,7 @@ module BABYLON {
             return false;
             return false;
         }
         }
 
 
-        public getAlphaTestTexture(): BaseTexture {
+        public getAlphaTestTexture(): Nullable<BaseTexture> {
             return null;
             return null;
         }
         }
 
 
@@ -146,7 +146,7 @@ module BABYLON {
             defines._needNormals = MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights, this._disableLighting);
             defines._needNormals = MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights, this._disableLighting);
 
 
             // Values that need to be evaluated on every frame
             // Values that need to be evaluated on every frame
-            MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances);
+            MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false);
             
             
             // Attribs
             // Attribs
             MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true);
             MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true);
@@ -227,7 +227,7 @@ module BABYLON {
                         indexParameters: { maxSimultaneousLights: this.maxSimultaneousLights }
                         indexParameters: { maxSimultaneousLights: this.maxSimultaneousLights }
                     }, engine), defines);
                     }, engine), defines);
             }
             }
-            if (!subMesh.effect.isReady()) {
+            if (!subMesh.effect || !subMesh.effect.isReady()) {
                 return false;
                 return false;
             }
             }
 
 
@@ -246,6 +246,9 @@ module BABYLON {
             }
             }
 
 
             var effect = subMesh.effect;
             var effect = subMesh.effect;
+            if (!effect) {
+                return;
+            }
             this._activeEffect = effect;
             this._activeEffect = effect;
 
 
             // Matrices        
             // Matrices        
@@ -297,7 +300,7 @@ module BABYLON {
                     this._activeEffect.setFloat("pointSize", this.pointSize);
                     this._activeEffect.setFloat("pointSize", this.pointSize);
                 }
                 }
 
 
-                this._activeEffect.setVector3("vEyePosition", scene._mirroredCameraPosition ? scene._mirroredCameraPosition : scene.activeCamera.position);                
+                this._activeEffect.setVector3("vEyePosition", scene._mirroredCameraPosition ? scene._mirroredCameraPosition : (<Camera>scene.activeCamera).position);                
             }
             }
 
 
             this._activeEffect.setColor4("vDiffuseColor", this.diffuseColor, this.alpha * mesh.visibility);
             this._activeEffect.setColor4("vDiffuseColor", this.diffuseColor, this.alpha * mesh.visibility);

+ 7 - 4
materialsLibrary/src/triPlanar/babylon.triPlanarMaterial.ts

@@ -99,7 +99,7 @@ module BABYLON {
             return false;
             return false;
         }
         }
 
 
-        public getAlphaTestTexture(): BaseTexture {
+        public getAlphaTestTexture(): Nullable<BaseTexture> {
             return null;
             return null;
         }
         }
 
 
@@ -167,7 +167,7 @@ module BABYLON {
             defines._needNormals = MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights, this._disableLighting);
             defines._needNormals = MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights, this._disableLighting);
 
 
             // Values that need to be evaluated on every frame
             // Values that need to be evaluated on every frame
-            MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances);
+            MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false);
             
             
             // Attribs
             // Attribs
             MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true);
             MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true);
@@ -239,7 +239,7 @@ module BABYLON {
                         indexParameters: { maxSimultaneousLights: this.maxSimultaneousLights }
                         indexParameters: { maxSimultaneousLights: this.maxSimultaneousLights }
                     }, engine), defines);
                     }, engine), defines);
             }
             }
-            if (!subMesh.effect.isReady()) {
+            if (!subMesh.effect || !subMesh.effect.isReady()) {
                 return false;
                 return false;
             }
             }
 
 
@@ -258,6 +258,9 @@ module BABYLON {
             }
             }
 
 
             var effect = subMesh.effect;
             var effect = subMesh.effect;
+            if (!effect) {
+                return;
+            }
             this._activeEffect = effect;
             this._activeEffect = effect;
 
 
             // Matrices        
             // Matrices        
@@ -297,7 +300,7 @@ module BABYLON {
                     this._activeEffect.setFloat("pointSize", this.pointSize);
                     this._activeEffect.setFloat("pointSize", this.pointSize);
                 }
                 }
 
 
-                this._activeEffect.setVector3("vEyePosition", scene._mirroredCameraPosition ? scene._mirroredCameraPosition : scene.activeCamera.position);                
+                this._activeEffect.setVector3("vEyePosition", scene._mirroredCameraPosition ? scene._mirroredCameraPosition : (<Camera>scene.activeCamera).position);                
             }
             }
 
 
             this._activeEffect.setColor4("vDiffuseColor", this.diffuseColor, this.alpha * mesh.visibility);
             this._activeEffect.setColor4("vDiffuseColor", this.diffuseColor, this.alpha * mesh.visibility);

+ 2 - 1
materialsLibrary/src/tsconfig.json

@@ -6,6 +6,7 @@
     "noImplicitAny": true,
     "noImplicitAny": true,
     "noImplicitReturns": true,
     "noImplicitReturns": true,
     "noImplicitThis": true,
     "noImplicitThis": true,
-    "noUnusedLocals": true
+    "noUnusedLocals": true,
+    "strictNullChecks": true
   }
   }
 }
 }

+ 17 - 9
materialsLibrary/src/water/babylon.waterMaterial.ts

@@ -138,7 +138,7 @@ module BABYLON {
 		/*
 		/*
 		* Private members
 		* Private members
 		*/
 		*/
-        private _mesh: AbstractMesh = null;
+        private _mesh: Nullable<AbstractMesh> = null;
 
 
         private _refractionRTT: RenderTargetTexture;
         private _refractionRTT: RenderTargetTexture;
         private _reflectionRTT: RenderTargetTexture;
         private _reflectionRTT: RenderTargetTexture;
@@ -191,8 +191,13 @@ module BABYLON {
 
 
         // Methods
         // Methods
         public addToRenderList(node: any): void {
         public addToRenderList(node: any): void {
-            this._refractionRTT.renderList.push(node);
-            this._reflectionRTT.renderList.push(node);
+            if (this._refractionRTT.renderList) {
+                this._refractionRTT.renderList.push(node);
+            }
+
+            if (this._reflectionRTT.renderList) {
+                this._reflectionRTT.renderList.push(node);
+            }
         }
         }
 
 
         public enableRenderTargets(enable: boolean): void {
         public enableRenderTargets(enable: boolean): void {
@@ -202,7 +207,7 @@ module BABYLON {
             this._reflectionRTT.refreshRate = refreshRate;
             this._reflectionRTT.refreshRate = refreshRate;
         }
         }
 
 
-        public getRenderList(): AbstractMesh[] {
+        public getRenderList(): Nullable<AbstractMesh[]> {
             return this._refractionRTT.renderList;
             return this._refractionRTT.renderList;
         }
         }
 
 
@@ -218,7 +223,7 @@ module BABYLON {
             return false;
             return false;
         }
         }
 
 
-        public getAlphaTestTexture(): BaseTexture {
+        public getAlphaTestTexture(): Nullable<BaseTexture> {
             return null;
             return null;
         }
         }
 
 
@@ -263,7 +268,7 @@ module BABYLON {
                 }
                 }
             }
             }
 
 
-            MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances);
+            MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false);
 
 
             MaterialHelper.PrepareDefinesForMisc(mesh, scene, this._useLogarithmicDepth, this.pointsCloud, this.fogEnabled, defines);
             MaterialHelper.PrepareDefinesForMisc(mesh, scene, this._useLogarithmicDepth, this.pointsCloud, this.fogEnabled, defines);
 
 
@@ -373,7 +378,7 @@ module BABYLON {
                     }, engine), defines);
                     }, engine), defines);
 
 
             }
             }
-            if (!subMesh.effect.isReady()) {
+            if (!subMesh.effect || !subMesh.effect.isReady()) {
                 return false;
                 return false;
             }
             }
 
 
@@ -392,6 +397,9 @@ module BABYLON {
             }
             }
 
 
             var effect = subMesh.effect;
             var effect = subMesh.effect;
+            if (!effect || !this._mesh) {
+                return;
+            }
             this._activeEffect = effect;
             this._activeEffect = effect;
 
 
             // Matrices        
             // Matrices        
@@ -417,7 +425,7 @@ module BABYLON {
                     this._activeEffect.setFloat("pointSize", this.pointSize);
                     this._activeEffect.setFloat("pointSize", this.pointSize);
                 }
                 }
 
 
-                this._activeEffect.setVector3("vEyePosition", scene._mirroredCameraPosition ? scene._mirroredCameraPosition : scene.activeCamera.position);
+                this._activeEffect.setVector3("vEyePosition", scene._mirroredCameraPosition ? scene._mirroredCameraPosition : (<Camera>scene.activeCamera).position);
             }
             }
 
 
             this._activeEffect.setColor4("vDiffuseColor", this.diffuseColor, this.alpha * mesh.visibility);
             this._activeEffect.setColor4("vDiffuseColor", this.diffuseColor, this.alpha * mesh.visibility);
@@ -485,7 +493,7 @@ module BABYLON {
             this._reflectionRTT.ignoreCameraViewport = true;
             this._reflectionRTT.ignoreCameraViewport = true;
 
 
             var isVisible: boolean;
             var isVisible: boolean;
-            var clipPlane: Plane = null;
+            var clipPlane: Nullable<Plane> = null;
             var savedViewMatrix: Matrix;
             var savedViewMatrix: Matrix;
             var mirrorMatrix = Matrix.Zero();
             var mirrorMatrix = Matrix.Zero();
 
 

+ 3 - 7
src/Engine/babylon.engine.ts

@@ -1086,12 +1086,8 @@
 
 
             // Constants
             // Constants
             this._gl.HALF_FLOAT_OES = 0x8D61; // Half floating-point type (16-bit).
             this._gl.HALF_FLOAT_OES = 0x8D61; // Half floating-point type (16-bit).
-            if (this._gl.RGBA16F !== 0x881A) {
-                this._gl.RGBA16F = 0x881A; // RGBA 16-bit floating-point color-renderable internal sized format.
-            }
-            if (this._gl.RGBA32F !== 0x8814) {
-                this._gl.RGBA32F = 0x8814; // RGBA 32-bit floating-point color-renderable internal sized format.
-            }
+            (<any>this._gl.RGBA16F) = 0x881A; // RGBA 16-bit floating-point color-renderable internal sized format.
+            (<any>this._gl.RGBA32F) = 0x8814; // RGBA 32-bit floating-point color-renderable internal sized format.
             this._gl.DEPTH24_STENCIL8 = 35056;
             this._gl.DEPTH24_STENCIL8 = 35056;
 
 
             // Extensions
             // Extensions
@@ -1316,7 +1312,7 @@
             return this._drawCalls;
             return this._drawCalls;
         }
         }
 
 
-        public getDepthFunction(): number {
+        public getDepthFunction(): Nullable<number> {
             return this._depthCullingState.depthFunc;
             return this._depthCullingState.depthFunc;
         }
         }
 
 

+ 2 - 2
src/Layer/babylon.layer.ts

@@ -60,12 +60,12 @@
             this._onAfterRenderObserver = this.onAfterRenderObservable.add(callback);
             this._onAfterRenderObserver = this.onAfterRenderObservable.add(callback);
         }
         }
 
 
-        constructor(public name: string, imgUrl: string, scene: Scene, isBackground?: boolean, color?: Color4) {
+        constructor(public name: string, imgUrl: Nullable<string>, scene: Nullable<Scene>, isBackground?: boolean, color?: Color4) {
             this.texture = imgUrl ? new Texture(imgUrl, scene, true) : null;
             this.texture = imgUrl ? new Texture(imgUrl, scene, true) : null;
             this.isBackground = isBackground === undefined ? true : isBackground;
             this.isBackground = isBackground === undefined ? true : isBackground;
             this.color = color === undefined ? new Color4(1, 1, 1, 1) : color;
             this.color = color === undefined ? new Color4(1, 1, 1, 1) : color;
             
             
-            this._scene = scene || Engine.LastCreatedScene;
+            this._scene = <Scene>(scene || Engine.LastCreatedScene);
             this._scene.layers.push(this);
             this._scene.layers.push(this);
 
 
             var engine = this._scene.getEngine();
             var engine = this._scene.getEngine();

+ 4 - 4
src/Materials/PBR/babylon.pbrMaterial.ts

@@ -496,13 +496,13 @@
         /**
         /**
          * Gets the Color Grading 2D Lookup Texture.
          * Gets the Color Grading 2D Lookup Texture.
          */
          */
-        public get cameraColorGradingTexture(): BaseTexture {
+        public get cameraColorGradingTexture(): Nullable<BaseTexture> {
             return this._imageProcessingConfiguration.colorGradingTexture;
             return this._imageProcessingConfiguration.colorGradingTexture;
         }
         }
         /**
         /**
          * Sets the Color Grading 2D Lookup Texture.
          * Sets the Color Grading 2D Lookup Texture.
          */
          */
-        public set cameraColorGradingTexture(value: BaseTexture) {
+        public set cameraColorGradingTexture(value: Nullable<BaseTexture>) {
             this._imageProcessingConfiguration.colorGradingTexture = value;
             this._imageProcessingConfiguration.colorGradingTexture = value;
         }
         }
 
 
@@ -512,7 +512,7 @@
          * These are similar to controls found in many professional imaging or colorist software. The global controls are applied to the entire image. For advanced tuning, extra controls are provided to adjust the shadow, midtone and highlight areas of the image; 
          * These are similar to controls found in many professional imaging or colorist software. The global controls are applied to the entire image. For advanced tuning, extra controls are provided to adjust the shadow, midtone and highlight areas of the image; 
          * corresponding to low luminance, medium luminance, and high luminance areas respectively.
          * corresponding to low luminance, medium luminance, and high luminance areas respectively.
          */
          */
-        public get cameraColorCurves(): ColorCurves {
+        public get cameraColorCurves(): Nullable<ColorCurves> {
             return this._imageProcessingConfiguration.colorCurves;
             return this._imageProcessingConfiguration.colorCurves;
         }
         }
         /**
         /**
@@ -521,7 +521,7 @@
          * These are similar to controls found in many professional imaging or colorist software. The global controls are applied to the entire image. For advanced tuning, extra controls are provided to adjust the shadow, midtone and highlight areas of the image; 
          * These are similar to controls found in many professional imaging or colorist software. The global controls are applied to the entire image. For advanced tuning, extra controls are provided to adjust the shadow, midtone and highlight areas of the image; 
          * corresponding to low luminance, medium luminance, and high luminance areas respectively.
          * corresponding to low luminance, medium luminance, and high luminance areas respectively.
          */
          */
-        public set cameraColorCurves(value: ColorCurves) {
+        public set cameraColorCurves(value: Nullable<ColorCurves>) {
             this._imageProcessingConfiguration.colorCurves = value;
             this._imageProcessingConfiguration.colorCurves = value;
         }
         }
 
 

+ 1 - 1
src/Materials/Textures/babylon.dynamicTexture.ts

@@ -7,7 +7,7 @@ module BABYLON {
         private _context: CanvasRenderingContext2D;
         private _context: CanvasRenderingContext2D;
         private _engine: Engine;
         private _engine: Engine;
 
 
-        constructor(name: string, options: any, scene: Scene, generateMipMaps: boolean, samplingMode: number = Texture.TRILINEAR_SAMPLINGMODE, format: number = Engine.TEXTUREFORMAT_RGBA) {
+        constructor(name: string, options: any, scene: Nullable<Scene> = null, generateMipMaps: boolean, samplingMode: number = Texture.TRILINEAR_SAMPLINGMODE, format: number = Engine.TEXTUREFORMAT_RGBA) {
             super(null, scene, !generateMipMaps, undefined, samplingMode, undefined, undefined, undefined, undefined, format);
             super(null, scene, !generateMipMaps, undefined, samplingMode, undefined, undefined, undefined, undefined, format);
 
 
             this.name = name;
             this.name = name;

+ 9 - 4
src/Materials/babylon.imageProcessingConfiguration.ts

@@ -30,7 +30,7 @@ module BABYLON {
          * Color curves setup used in the effect if colorCurvesEnabled is set to true 
          * Color curves setup used in the effect if colorCurvesEnabled is set to true 
          */
          */
         @serializeAsColorCurves()
         @serializeAsColorCurves()
-        public colorCurves = new ColorCurves();
+        public colorCurves: Nullable<ColorCurves> = new ColorCurves();
 
 
         @serialize()
         @serialize()
         private _colorCurvesEnabled = false;
         private _colorCurvesEnabled = false;
@@ -56,7 +56,7 @@ module BABYLON {
          * Color grading LUT texture used in the effect if colorGradingEnabled is set to true 
          * Color grading LUT texture used in the effect if colorGradingEnabled is set to true 
          */
          */
         @serializeAsTexture()
         @serializeAsTexture()
-        public colorGradingTexture: BaseTexture;
+        public colorGradingTexture: Nullable<BaseTexture>;
 
 
         @serialize()
         @serialize()
         private _colorGradingEnabled = false;
         private _colorGradingEnabled = false;
@@ -354,7 +354,12 @@ module BABYLON {
             defines.EXPOSURE = (this.exposure !== 1.0);
             defines.EXPOSURE = (this.exposure !== 1.0);
             defines.COLORCURVES = (this.colorCurvesEnabled && !!this.colorCurves);
             defines.COLORCURVES = (this.colorCurvesEnabled && !!this.colorCurves);
             defines.COLORGRADING = (this.colorGradingEnabled && !!this.colorGradingTexture);
             defines.COLORGRADING = (this.colorGradingEnabled && !!this.colorGradingTexture);
-            defines.COLORGRADING3D = defines.COLORGRADING && ((<Scene>this.colorGradingTexture.getScene()).getEngine().webGLVersion > 1);
+            if (defines.COLORGRADING) {
+                let texture = <BaseTexture>this.colorGradingTexture;
+                defines.COLORGRADING3D = ((<Scene>texture.getScene()).getEngine().webGLVersion > 1) ? true : false;                 
+            } else {
+                defines.COLORGRADING3D = false;
+            }
             defines.SAMPLER3DGREENDEPTH = this.colorGradingWithGreenDepth;
             defines.SAMPLER3DGREENDEPTH = this.colorGradingWithGreenDepth;
             defines.SAMPLER3DBGRMAP = this.colorGradingBGR;
             defines.SAMPLER3DBGRMAP = this.colorGradingBGR;
             defines.IMAGEPROCESSINGPOSTPROCESS = this.applyByPostProcess;
             defines.IMAGEPROCESSINGPOSTPROCESS = this.applyByPostProcess;
@@ -375,7 +380,7 @@ module BABYLON {
          */
          */
         public bind(effect: Effect, aspectRatio = 1) : void {
         public bind(effect: Effect, aspectRatio = 1) : void {
             // Color Curves
             // Color Curves
-            if (this._colorCurvesEnabled) {
+            if (this._colorCurvesEnabled && this.colorCurves) {
                 ColorCurves.Bind(this.colorCurves, effect);
                 ColorCurves.Bind(this.colorCurves, effect);
             }
             }
 
 

+ 4 - 4
src/Materials/babylon.standardMaterial.ts

@@ -421,13 +421,13 @@ module BABYLON {
         /**
         /**
          * Gets the Color Grading 2D Lookup Texture.
          * Gets the Color Grading 2D Lookup Texture.
          */
          */
-        public get cameraColorGradingTexture(): BaseTexture {
+        public get cameraColorGradingTexture(): Nullable<BaseTexture> {
             return this._imageProcessingConfiguration.colorGradingTexture;
             return this._imageProcessingConfiguration.colorGradingTexture;
         }
         }
         /**
         /**
          * Sets the Color Grading 2D Lookup Texture.
          * Sets the Color Grading 2D Lookup Texture.
          */
          */
-        public set cameraColorGradingTexture(value: BaseTexture) {
+        public set cameraColorGradingTexture(value: Nullable<BaseTexture> ) {
             this._imageProcessingConfiguration.colorGradingTexture = value;
             this._imageProcessingConfiguration.colorGradingTexture = value;
         }
         }
 
 
@@ -437,7 +437,7 @@ module BABYLON {
          * These are similar to controls found in many professional imaging or colorist software. The global controls are applied to the entire image. For advanced tuning, extra controls are provided to adjust the shadow, midtone and highlight areas of the image; 
          * These are similar to controls found in many professional imaging or colorist software. The global controls are applied to the entire image. For advanced tuning, extra controls are provided to adjust the shadow, midtone and highlight areas of the image; 
          * corresponding to low luminance, medium luminance, and high luminance areas respectively.
          * corresponding to low luminance, medium luminance, and high luminance areas respectively.
          */
          */
-        public get cameraColorCurves(): ColorCurves {
+        public get cameraColorCurves(): Nullable<ColorCurves> {
             return this._imageProcessingConfiguration.colorCurves;
             return this._imageProcessingConfiguration.colorCurves;
         }
         }
         /**
         /**
@@ -446,7 +446,7 @@ module BABYLON {
          * These are similar to controls found in many professional imaging or colorist software. The global controls are applied to the entire image. For advanced tuning, extra controls are provided to adjust the shadow, midtone and highlight areas of the image; 
          * These are similar to controls found in many professional imaging or colorist software. The global controls are applied to the entire image. For advanced tuning, extra controls are provided to adjust the shadow, midtone and highlight areas of the image; 
          * corresponding to low luminance, medium luminance, and high luminance areas respectively.
          * corresponding to low luminance, medium luminance, and high luminance areas respectively.
          */
          */
-        public set cameraColorCurves(value: ColorCurves) {
+        public set cameraColorCurves(value: Nullable<ColorCurves>) {
             this._imageProcessingConfiguration.colorCurves = value;
             this._imageProcessingConfiguration.colorCurves = value;
         }        
         }        
 
 

+ 4 - 4
src/Physics/babylon.physicsImpostor.ts

@@ -45,7 +45,7 @@ module BABYLON {
         private _deltaRotationConjugated: Quaternion;
         private _deltaRotationConjugated: Quaternion;
 
 
         //If set, this is this impostor's parent
         //If set, this is this impostor's parent
-        private _parent: PhysicsImpostor;
+        private _parent: Nullable<PhysicsImpostor>;
 
 
         private _isDisposed = false;
         private _isDisposed = false;
 
 
@@ -199,11 +199,11 @@ module BABYLON {
             return (this._parent && !this._options.ignoreParent) ? this._parent.physicsBody : this._physicsBody;
             return (this._parent && !this._options.ignoreParent) ? this._parent.physicsBody : this._physicsBody;
         }
         }
 
 
-        public get parent(): PhysicsImpostor {
-            return !this._options.ignoreParent && this._parent;
+        public get parent(): Nullable<PhysicsImpostor> {
+            return !this._options.ignoreParent && this._parent ? this._parent : null;
         }
         }
 
 
-        public set parent(value: PhysicsImpostor) {
+        public set parent(value: Nullable<PhysicsImpostor>) {
             this._parent = value;
             this._parent = value;
         }
         }
 
 

+ 4 - 4
src/PostProcess/babylon.imageProcessingPostProcess.ts

@@ -78,13 +78,13 @@
         /**
         /**
          * Gets Color curves setup used in the effect if colorCurvesEnabled is set to true .
          * Gets Color curves setup used in the effect if colorCurvesEnabled is set to true .
          */
          */
-        public get colorCurves(): ColorCurves {
+        public get colorCurves(): Nullable<ColorCurves> {
             return this.imageProcessingConfiguration.colorCurves;
             return this.imageProcessingConfiguration.colorCurves;
         }
         }
         /**
         /**
          * Sets Color curves setup used in the effect if colorCurvesEnabled is set to true .
          * Sets Color curves setup used in the effect if colorCurvesEnabled is set to true .
          */
          */
-        public set colorCurves(value: ColorCurves) {
+        public set colorCurves(value: Nullable<ColorCurves>) {
             this.imageProcessingConfiguration.colorCurves = value;
             this.imageProcessingConfiguration.colorCurves = value;
         }
         }
 
 
@@ -104,13 +104,13 @@
         /**
         /**
          * Gets Color grading LUT texture used in the effect if colorGradingEnabled is set to true.
          * Gets Color grading LUT texture used in the effect if colorGradingEnabled is set to true.
          */
          */
-        public get colorGradingTexture(): BaseTexture {
+        public get colorGradingTexture(): Nullable<BaseTexture> {
             return this.imageProcessingConfiguration.colorGradingTexture;
             return this.imageProcessingConfiguration.colorGradingTexture;
         }
         }
         /**
         /**
          * Sets Color grading LUT texture used in the effect if colorGradingEnabled is set to true.
          * Sets Color grading LUT texture used in the effect if colorGradingEnabled is set to true.
          */
          */
-        public set colorGradingTexture(value: BaseTexture) {
+        public set colorGradingTexture(value: Nullable<BaseTexture>) {
             this.imageProcessingConfiguration.colorGradingTexture = value;
             this.imageProcessingConfiguration.colorGradingTexture = value;
         }
         }
 
 

+ 6 - 6
src/Sprites/babylon.spriteManager.ts

@@ -14,7 +14,7 @@
         */
         */
         public onDisposeObservable = new Observable<SpriteManager>();
         public onDisposeObservable = new Observable<SpriteManager>();
 
 
-        private _onDisposeObserver: Observer<SpriteManager>;
+        private _onDisposeObserver: Nullable<Observer<SpriteManager>>;
         public set onDispose(callback: () => void) {
         public set onDispose(callback: () => void) {
             if (this._onDisposeObserver) {
             if (this._onDisposeObserver) {
                 this.onDisposeObservable.remove(this._onDisposeObserver);
                 this.onDisposeObservable.remove(this._onDisposeObserver);
@@ -137,12 +137,12 @@
             this._vertexData[arrayOffset + 15] = sprite.color.a;
             this._vertexData[arrayOffset + 15] = sprite.color.a;
         }
         }
 
 
-        public intersects(ray: Ray, camera:Camera, predicate?: (sprite: Sprite) => boolean, fastCheck?: boolean): PickingInfo {
+        public intersects(ray: Ray, camera:Camera, predicate?: (sprite: Sprite) => boolean, fastCheck?: boolean): Nullable<PickingInfo> {
             var count = Math.min(this._capacity, this.sprites.length);
             var count = Math.min(this._capacity, this.sprites.length);
             var min = Vector3.Zero();
             var min = Vector3.Zero();
             var max = Vector3.Zero();
             var max = Vector3.Zero();
             var distance = Number.MAX_VALUE;
             var distance = Number.MAX_VALUE;
-            var currentSprite: Sprite;
+            var currentSprite: Nullable<Sprite> = null;
             var cameraSpacePosition = Vector3.Zero();
             var cameraSpacePosition = Vector3.Zero();
             var cameraView = camera.getViewMatrix();
             var cameraView = camera.getViewMatrix();
 
 
@@ -262,17 +262,17 @@
         public dispose(): void {
         public dispose(): void {
             if (this._buffer) {
             if (this._buffer) {
                 this._buffer.dispose();
                 this._buffer.dispose();
-                this._buffer = null;
+                (<any>this._buffer) = null;
             }
             }
 
 
             if (this._indexBuffer) {
             if (this._indexBuffer) {
                 this._scene.getEngine()._releaseBuffer(this._indexBuffer);
                 this._scene.getEngine()._releaseBuffer(this._indexBuffer);
-                this._indexBuffer = null;
+                (<any>this._indexBuffer) = null;
             }
             }
 
 
             if (this._spriteTexture) {
             if (this._spriteTexture) {
                 this._spriteTexture.dispose();
                 this._spriteTexture.dispose();
-                this._spriteTexture = null;
+                (<any>this._spriteTexture) = null;
             }
             }
 
 
             // Remove from scene
             // Remove from scene

+ 5 - 5
src/States/babylon.alphaCullingState.ts

@@ -5,9 +5,9 @@
         private _isBlendEquationParametersDirty = false;
         private _isBlendEquationParametersDirty = false;
         private _isBlendConstantsDirty = false;
         private _isBlendConstantsDirty = false;
         private _alphaBlend = false;
         private _alphaBlend = false;
-        private _blendFunctionParameters = new Array<number>(4);
-        private _blendEquationParameters = new Array<number>(2);
-        private _blendConstants = new Array<number>(4);
+        private _blendFunctionParameters = new Array<Nullable<number>>(4);
+        private _blendEquationParameters = new Array<Nullable<number>>(2);
+        private _blendConstants = new Array<Nullable<number>>(4);
 
 
         /**
         /**
          * Initializes the state.
          * Initializes the state.
@@ -123,7 +123,7 @@
 
 
             // Alpha function
             // Alpha function
             if (this._isBlendFunctionParametersDirty) {
             if (this._isBlendFunctionParametersDirty) {
-                gl.blendFuncSeparate(this._blendFunctionParameters[0], this._blendFunctionParameters[1], this._blendFunctionParameters[2], this._blendFunctionParameters[3]);
+                gl.blendFuncSeparate(<number>this._blendFunctionParameters[0], <number>this._blendFunctionParameters[1], <number>this._blendFunctionParameters[2], <number>this._blendFunctionParameters[3]);
                 this._isBlendFunctionParametersDirty = false;
                 this._isBlendFunctionParametersDirty = false;
             }
             }
 
 
@@ -135,7 +135,7 @@
 
 
             // Constants
             // Constants
             if (this._isBlendConstantsDirty) {
             if (this._isBlendConstantsDirty) {
-                gl.blendColor(this._blendConstants[0], this._blendConstants[1], this._blendConstants[2], this._blendConstants[3]);
+                gl.blendColor(<number>this._blendConstants[0], <number>this._blendConstants[1], <number>this._blendConstants[2], <number>this._blendConstants[3]);
                 this._isBlendConstantsDirty = false;
                 this._isBlendConstantsDirty = false;
             }                    
             }                    
         }
         }

+ 0 - 0
src/States/babylon.depthCullingState.ts


Some files were not shown because too many files changed in this diff