Explorar o código

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

David Catuhe %!s(int64=7) %!d(string=hai) anos
pai
achega
4a513abe21
Modificáronse 100 ficheiros con 13623 adicións e 13308 borrados
  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

A diferenza do arquivo foi suprimida porque é demasiado grande
+ 3834 - 3834
dist/preview release/babylon.d.ts


A diferenza do arquivo foi suprimida porque é demasiado grande
+ 20 - 20
dist/preview release/babylon.js


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

@@ -8597,12 +8597,8 @@ var BABYLON;
             }
             // Constants
             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;
             // Extensions
             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.COLORCURVES = (this.colorCurvesEnabled && !!this.colorCurves);
             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.SAMPLER3DBGRMAP = this.colorGradingBGR;
             defines.IMAGEPROCESSINGPOSTPROCESS = this.applyByPostProcess;
@@ -32143,7 +32145,7 @@ var BABYLON;
         ImageProcessingConfiguration.prototype.bind = function (effect, aspectRatio) {
             if (aspectRatio === void 0) { aspectRatio = 1; }
             // Color Curves
-            if (this._colorCurvesEnabled) {
+            if (this._colorCurvesEnabled && this.colorCurves) {
                 BABYLON.ColorCurves.Bind(this.colorCurves, effect);
             }
             // Vignette
@@ -42611,7 +42613,7 @@ var BABYLON;
             var min = BABYLON.Vector3.Zero();
             var max = BABYLON.Vector3.Zero();
             var distance = Number.MAX_VALUE;
-            var currentSprite;
+            var currentSprite = null;
             var cameraSpacePosition = BABYLON.Vector3.Zero();
             var cameraView = camera.getViewMatrix();
             for (var index = 0; index < count; index++) {
@@ -50093,6 +50095,7 @@ var BABYLON;
     var DynamicTexture = /** @class */ (function (_super) {
         __extends(DynamicTexture, _super);
         function DynamicTexture(name, options, scene, generateMipMaps, samplingMode, format) {
+            if (scene === void 0) { scene = null; }
             if (samplingMode === void 0) { samplingMode = BABYLON.Texture.TRILINEAR_SAMPLINGMODE; }
             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;
@@ -65541,7 +65544,7 @@ var BABYLON;
         });
         Object.defineProperty(PhysicsImpostor.prototype, "parent", {
             get: function () {
-                return !this._options.ignoreParent && this._parent;
+                return !this._options.ignoreParent && this._parent ? this._parent : null;
             },
             set: function (value) {
                 this._parent = value;
@@ -73564,7 +73567,7 @@ var BABYLON;
             this.texture = imgUrl ? new BABYLON.Texture(imgUrl, scene, true) : null;
             this.isBackground = isBackground === undefined ? true : isBackground;
             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);
             var engine = this._scene.getEngine();
             // VBO

A diferenza do arquivo foi suprimida porque é demasiado grande
+ 3834 - 3834
dist/preview release/babylon.module.d.ts


A diferenza do arquivo foi suprimida porque é demasiado grande
+ 20 - 20
dist/preview release/babylon.worker.js


A diferenza do arquivo foi suprimida porque é demasiado grande
+ 2527 - 2527
dist/preview release/customConfigurations/minimalGLTFViewer/babylon.d.ts


A diferenza do arquivo foi suprimida porque é demasiado grande
+ 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
             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;
             // Extensions
             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.COLORCURVES = (this.colorCurvesEnabled && !!this.colorCurves);
             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.SAMPLER3DBGRMAP = this.colorGradingBGR;
             defines.IMAGEPROCESSINGPOSTPROCESS = this.applyByPostProcess;
@@ -32143,7 +32145,7 @@ var BABYLON;
         ImageProcessingConfiguration.prototype.bind = function (effect, aspectRatio) {
             if (aspectRatio === void 0) { aspectRatio = 1; }
             // Color Curves
-            if (this._colorCurvesEnabled) {
+            if (this._colorCurvesEnabled && this.colorCurves) {
                 BABYLON.ColorCurves.Bind(this.colorCurves, effect);
             }
             // Vignette
@@ -42611,7 +42613,7 @@ var BABYLON;
             var min = BABYLON.Vector3.Zero();
             var max = BABYLON.Vector3.Zero();
             var distance = Number.MAX_VALUE;
-            var currentSprite;
+            var currentSprite = null;
             var cameraSpacePosition = BABYLON.Vector3.Zero();
             var cameraView = camera.getViewMatrix();
             for (var index = 0; index < count; index++) {
@@ -50093,6 +50095,7 @@ var BABYLON;
     var DynamicTexture = /** @class */ (function (_super) {
         __extends(DynamicTexture, _super);
         function DynamicTexture(name, options, scene, generateMipMaps, samplingMode, format) {
+            if (scene === void 0) { scene = null; }
             if (samplingMode === void 0) { samplingMode = BABYLON.Texture.TRILINEAR_SAMPLINGMODE; }
             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;
@@ -65541,7 +65544,7 @@ var BABYLON;
         });
         Object.defineProperty(PhysicsImpostor.prototype, "parent", {
             get: function () {
-                return !this._options.ignoreParent && this._parent;
+                return !this._options.ignoreParent && this._parent ? this._parent : null;
             },
             set: function (value) {
                 this._parent = value;
@@ -73564,7 +73567,7 @@ var BABYLON;
             this.texture = imgUrl ? new BABYLON.Texture(imgUrl, scene, true) : null;
             this.isBackground = isBackground === undefined ? true : isBackground;
             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);
             var engine = this._scene.getEngine();
             // VBO
@@ -74669,9 +74672,9 @@ var BABYLON;
                 var attribs = [BABYLON.VertexBuffer.PositionKind, BABYLON.VertexBuffer.NormalKind];
                 // Defines
                 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;
             }
             this._renderId = scene.getRenderId();
@@ -74685,6 +74688,9 @@ var BABYLON;
                 return;
             }
             var effect = subMesh.effect;
+            if (!effect) {
+                return;
+            }
             this._activeEffect = effect;
             // Matrices
             this.bindOnlyWorldMatrix(world);
@@ -75051,7 +75057,7 @@ var BABYLON;
              * Sets the Color Grading 2D Lookup Texture.
              */
             set: function (value) {
-                this._imageProcessingConfiguration.colorGradingTexture = value;
+                this.imageProcessingConfiguration.colorGradingTexture = value;
             },
             enumerable: true,
             configurable: true
@@ -75064,7 +75070,7 @@ var BABYLON;
              * corresponding to low luminance, medium luminance, and high luminance areas respectively.
              */
             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).
@@ -75073,7 +75079,7 @@ var BABYLON;
              * corresponding to low luminance, medium luminance, and high luminance areas respectively.
              */
             set: function (value) {
-                this._imageProcessingConfiguration.colorCurves = value;
+                this.imageProcessingConfiguration.colorCurves = value;
             },
             enumerable: true,
             configurable: true
@@ -75254,7 +75260,7 @@ var BABYLON;
                 }, engine), defines);
                 this.buildUniformLayout();
             }
-            if (!subMesh.effect.isReady()) {
+            if (!subMesh.effect || !subMesh.effect.isReady()) {
                 return false;
             }
             defines._renderId = scene.getRenderId();
@@ -75309,6 +75315,9 @@ var BABYLON;
                 return;
             }
             var effect = subMesh.effect;
+            if (!effect) {
+                return;
+            }
             this._activeEffect = effect;
             // Matrices
             this.bindOnlyWorldMatrix(world);
@@ -75381,7 +75390,6 @@ var BABYLON;
             }
             this._uniformBuffer.update();
             this._afterBind(mesh);
-            scene = null;
         };
         /**
          * Dispose the material.

A diferenza do arquivo foi suprimida porque é demasiado grande
+ 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;
         _rootContainer: Container;
         _lastPickedControl: Control;
-        _lastControlOver: Control;
-        _lastControlDown: Control;
-        _capturingControl: Control;
+        _lastControlOver: Nullable<Control>;
+        _lastControlDown: Nullable<Control>;
+        _capturingControl: Nullable<Control>;
         _shouldBlockPointer: boolean;
-        _layerToDispose: Layer;
+        _layerToDispose: Nullable<Layer>;
         _linkedControls: Control[];
         private _isFullscreen;
         private _fullscreenViewport;
@@ -33,10 +33,10 @@ declare module BABYLON.GUI {
         idealWidth: number;
         idealHeight: number;
         renderAtIdealSize: boolean;
-        readonly layer: Layer;
+        readonly layer: Nullable<Layer>;
         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;
         markAsDirty(): void;
         addControl(control: Control): AdvancedDynamicTexture;
@@ -53,7 +53,7 @@ declare module BABYLON.GUI {
         private _manageFocus();
         private _attachToOnPointerOut(scene);
         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 _TempCompose1;
         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 _alphaSet;
         private _zIndex;
-        _root: Container;
+        _root: Nullable<Container>;
         _host: AdvancedDynamicTexture;
-        parent: Container;
+        parent: Nullable<Container>;
         _currentMeasure: Measure;
         private _fontFamily;
         private _fontStyle;
@@ -168,7 +168,7 @@ declare module BABYLON.GUI {
         private _cachedOffsetX;
         private _cachedOffsetY;
         private _isVisible;
-        _linkedMesh: AbstractMesh;
+        _linkedMesh: Nullable<AbstractMesh>;
         private _fontSet;
         private _dummyVector2;
         private _downCount;
@@ -260,12 +260,12 @@ declare module BABYLON.GUI {
         getLocalCoordinatesToRef(globalCoordinates: Vector2, result: Vector2): Control;
         getParentLocalCoordinates(globalCoordinates: Vector2): Vector2;
         moveToVector3(position: Vector3, scene: Scene): void;
-        linkWithMesh(mesh: AbstractMesh): void;
+        linkWithMesh(mesh: Nullable<AbstractMesh>): void;
         _moveToProjectedPosition(projectedPosition: Vector3): void;
         _markMatrixAsDirty(): void;
         _markAsDirty(): void;
         _markAllAsDirty(): void;
-        _link(root: Container, host: AdvancedDynamicTexture): void;
+        _link(root: Nullable<Container>, host: AdvancedDynamicTexture): void;
         protected _transform(context: CanvasRenderingContext2D): void;
         protected _applyStates(context: CanvasRenderingContext2D): void;
         protected _processMeasures(parentMeasure: Measure, context: CanvasRenderingContext2D): boolean;
@@ -323,8 +323,8 @@ declare module BABYLON.GUI {
         readonly children: Control[];
         constructor(name?: 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;
         addControl(control: Control): Container;
         removeControl(control: Control): Container;
@@ -332,7 +332,7 @@ declare module BABYLON.GUI {
         _markMatrixAsDirty(): void;
         _markAllAsDirty(): 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;
         _processPicking(x: number, y: number, type: number, buttonIndex: number): boolean;
         protected _clipForChildren(context: CanvasRenderingContext2D): void;
@@ -551,8 +551,8 @@ declare module BABYLON.GUI {
         stretch: number;
         domImage: HTMLImageElement;
         private _onImageLoaded();
-        source: string;
-        constructor(name?: string, url?: string);
+        source: Nullable<string>;
+        constructor(name?: string, url?: Nullable<string>);
         protected _getTypeName(): string;
         synchronizeSizeWithContent(): void;
         _draw(parentMeasure: Measure, context: CanvasRenderingContext2D): void;
@@ -699,13 +699,13 @@ declare module BABYLON.GUI {
         defaultButtonColor: string;
         defaultButtonBackground: string;
         protected _getTypeName(): string;
-        private _createKey(key, propertySet?);
+        private _createKey(key, propertySet);
         addKeysRow(keys: Array<string>, propertySets?: Array<KeyPropertySet>): void;
         private _connectedInputText;
         private _onFocusObserver;
         private _onBlurObserver;
         private _onKeyPressObserver;
-        readonly connectedInputText: InputText;
+        readonly connectedInputText: Nullable<InputText>;
         connect(input: InputText): void;
         disconnect(): void;
         static CreateDefaultLayout(): VirtualKeyboard;

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

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

A diferenza do arquivo foi suprimida porque é demasiado grande
+ 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;
         _rootContainer: Container;
         _lastPickedControl: Control;
-        _lastControlOver: Control;
-        _lastControlDown: Control;
-        _capturingControl: Control;
+        _lastControlOver: Nullable<Control>;
+        _lastControlDown: Nullable<Control>;
+        _capturingControl: Nullable<Control>;
         _shouldBlockPointer: boolean;
-        _layerToDispose: Layer;
+        _layerToDispose: Nullable<Layer>;
         _linkedControls: Control[];
         private _isFullscreen;
         private _fullscreenViewport;
@@ -38,10 +38,10 @@ declare module BABYLON.GUI {
         idealWidth: number;
         idealHeight: number;
         renderAtIdealSize: boolean;
-        readonly layer: Layer;
+        readonly layer: Nullable<Layer>;
         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;
         markAsDirty(): void;
         addControl(control: Control): AdvancedDynamicTexture;
@@ -58,7 +58,7 @@ declare module BABYLON.GUI {
         private _manageFocus();
         private _attachToOnPointerOut(scene);
         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 _TempCompose1;
         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 _alphaSet;
         private _zIndex;
-        _root: Container;
+        _root: Nullable<Container>;
         _host: AdvancedDynamicTexture;
-        parent: Container;
+        parent: Nullable<Container>;
         _currentMeasure: Measure;
         private _fontFamily;
         private _fontStyle;
@@ -173,7 +173,7 @@ declare module BABYLON.GUI {
         private _cachedOffsetX;
         private _cachedOffsetY;
         private _isVisible;
-        _linkedMesh: AbstractMesh;
+        _linkedMesh: Nullable<AbstractMesh>;
         private _fontSet;
         private _dummyVector2;
         private _downCount;
@@ -265,12 +265,12 @@ declare module BABYLON.GUI {
         getLocalCoordinatesToRef(globalCoordinates: Vector2, result: Vector2): Control;
         getParentLocalCoordinates(globalCoordinates: Vector2): Vector2;
         moveToVector3(position: Vector3, scene: Scene): void;
-        linkWithMesh(mesh: AbstractMesh): void;
+        linkWithMesh(mesh: Nullable<AbstractMesh>): void;
         _moveToProjectedPosition(projectedPosition: Vector3): void;
         _markMatrixAsDirty(): void;
         _markAsDirty(): void;
         _markAllAsDirty(): void;
-        _link(root: Container, host: AdvancedDynamicTexture): void;
+        _link(root: Nullable<Container>, host: AdvancedDynamicTexture): void;
         protected _transform(context: CanvasRenderingContext2D): void;
         protected _applyStates(context: CanvasRenderingContext2D): void;
         protected _processMeasures(parentMeasure: Measure, context: CanvasRenderingContext2D): boolean;
@@ -328,8 +328,8 @@ declare module BABYLON.GUI {
         readonly children: Control[];
         constructor(name?: 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;
         addControl(control: Control): Container;
         removeControl(control: Control): Container;
@@ -337,7 +337,7 @@ declare module BABYLON.GUI {
         _markMatrixAsDirty(): void;
         _markAllAsDirty(): 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;
         _processPicking(x: number, y: number, type: number, buttonIndex: number): boolean;
         protected _clipForChildren(context: CanvasRenderingContext2D): void;
@@ -556,8 +556,8 @@ declare module BABYLON.GUI {
         stretch: number;
         domImage: HTMLImageElement;
         private _onImageLoaded();
-        source: string;
-        constructor(name?: string, url?: string);
+        source: Nullable<string>;
+        constructor(name?: string, url?: Nullable<string>);
         protected _getTypeName(): string;
         synchronizeSizeWithContent(): void;
         _draw(parentMeasure: Measure, context: CanvasRenderingContext2D): void;
@@ -704,13 +704,13 @@ declare module BABYLON.GUI {
         defaultButtonColor: string;
         defaultButtonBackground: string;
         protected _getTypeName(): string;
-        private _createKey(key, propertySet?);
+        private _createKey(key, propertySet);
         addKeysRow(keys: Array<string>, propertySets?: Array<KeyPropertySet>): void;
         private _connectedInputText;
         private _onFocusObserver;
         private _onBlurObserver;
         private _onKeyPressObserver;
-        readonly connectedInputText: InputText;
+        readonly connectedInputText: Nullable<InputText>;
         connect(input: InputText): void;
         disconnect(): void;
         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.
          */
-        imageProcessingConfiguration: ImageProcessingConfiguration;
+        imageProcessingConfiguration: Nullable<ImageProcessingConfiguration>;
         /**
          * 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.
              */
             set: function (value) {
-                this._imageProcessingConfiguration.colorGradingTexture = value;
+                this.imageProcessingConfiguration.colorGradingTexture = value;
             },
             enumerable: true,
             configurable: true
@@ -314,7 +314,7 @@ var BABYLON;
              * corresponding to low luminance, medium luminance, and high luminance areas respectively.
              */
             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).
@@ -323,7 +323,7 @@ var BABYLON;
              * corresponding to low luminance, medium luminance, and high luminance areas respectively.
              */
             set: function (value) {
-                this._imageProcessingConfiguration.colorCurves = value;
+                this.imageProcessingConfiguration.colorCurves = value;
             },
             enumerable: true,
             configurable: true
@@ -504,7 +504,7 @@ var BABYLON;
                 }, engine), defines);
                 this.buildUniformLayout();
             }
-            if (!subMesh.effect.isReady()) {
+            if (!subMesh.effect || !subMesh.effect.isReady()) {
                 return false;
             }
             defines._renderId = scene.getRenderId();
@@ -559,6 +559,9 @@ var BABYLON;
                 return;
             }
             var effect = subMesh.effect;
+            if (!effect) {
+                return;
+            }
             this._activeEffect = effect;
             // Matrices
             this.bindOnlyWorldMatrix(world);
@@ -631,7 +634,6 @@ var BABYLON;
             }
             this._uniformBuffer.update();
             this._afterBind(mesh);
-            scene = null;
         };
         /**
          * Dispose the material.

A diferenza do arquivo foi suprimida porque é demasiado grande
+ 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);
         needAlphaBlending(): boolean;
         needAlphaTesting(): boolean;
-        getAlphaTestTexture(): BaseTexture;
+        getAlphaTestTexture(): Nullable<BaseTexture>;
         isReadyForSubMesh(mesh: AbstractMesh, subMesh: SubMesh, useInstances?: boolean): boolean;
         bindForSubMesh(world: Matrix, mesh: Mesh, subMesh: SubMesh): void;
         getAnimatables(): IAnimatable[];

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

@@ -102,7 +102,7 @@ var BABYLON;
             // Lights
             defines._needNormals = BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights, this._disableLighting);
             // 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
             BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true);
             // Get correct effect      
@@ -163,7 +163,7 @@ var BABYLON;
                     indexParameters: { maxSimultaneousLights: this.maxSimultaneousLights - 1 }
                 }, engine), defines);
             }
-            if (!subMesh.effect.isReady()) {
+            if (!subMesh.effect || !subMesh.effect.isReady()) {
                 return false;
             }
             this._renderId = scene.getRenderId();
@@ -177,6 +177,9 @@ var BABYLON;
                 return;
             }
             var effect = subMesh.effect;
+            if (!effect) {
+                return;
+            }
             this._activeEffect = effect;
             // Matrices        
             this.bindOnlyWorldMatrix(world);

A diferenza do arquivo foi suprimida porque é demasiado grande
+ 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.
          * @param configuration
          */
-        protected _attachImageProcessingConfiguration(configuration: ImageProcessingConfiguration): void;
+        protected _attachImageProcessingConfiguration(configuration: Nullable<ImageProcessingConfiguration>): void;
         /**
          * Gets wether the color curves effect is enabled.
          */
@@ -221,7 +221,7 @@ declare module BABYLON {
         /**
          * 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;
         protected _renderTargets: SmartArray<RenderTargetTexture>;
         protected _worldViewProjectionMatrix: Matrix;

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

@@ -564,7 +564,7 @@ var BABYLON;
             // Attribs
             BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true, true);
             // 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      
             if (defines.isDirty) {
                 defines.markAsProcessed();
@@ -671,7 +671,7 @@ var BABYLON;
                 }, engine), defines);
                 this.buildUniformLayout();
             }
-            if (!subMesh.effect.isReady()) {
+            if (!subMesh.effect || !subMesh.effect.isReady()) {
                 return false;
             }
             defines._renderId = scene.getRenderId();
@@ -732,6 +732,9 @@ var BABYLON;
                 return;
             }
             var effect = subMesh.effect;
+            if (!effect) {
+                return;
+            }
             this._activeEffect = effect;
             // Matrices        
             this.bindOnlyWorldMatrix(world);
@@ -1951,11 +1954,14 @@ vColor=color;\n\
                 return this._createdShaderName;
             this._isCreatedShader = false;
             CustomMaterial.ShaderIndexer++;
-            var name = name + "custom_" + CustomMaterial.ShaderIndexer;
+            var name = "custom_" + CustomMaterial.ShaderIndexer;
             this.ReviewUniform("uniform", uniforms);
             this.ReviewUniform("sampler", samplers);
             var fn_afterBind = this._afterBind;
             this._afterBind = function (m, e) {
+                if (!e) {
+                    return;
+                }
                 _this.AttachAfterBind(m, e);
                 try {
                     fn_afterBind(m, e);

A diferenza do arquivo foi suprimida porque é demasiado grande
+ 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 {
     class FireMaterial extends PushMaterial {
         private _diffuseTexture;
-        diffuseTexture: BaseTexture;
+        diffuseTexture: Nullable<BaseTexture>;
         private _distortionTexture;
-        distortionTexture: BaseTexture;
+        distortionTexture: Nullable<BaseTexture>;
         private _opacityTexture;
-        opacityTexture: BaseTexture;
+        opacityTexture: Nullable<BaseTexture>;
         diffuseColor: Color3;
         speed: number;
         private _scaledDiffuse;
@@ -15,7 +15,7 @@ declare module BABYLON {
         constructor(name: string, scene: Scene);
         needAlphaBlending(): boolean;
         needAlphaTesting(): boolean;
-        getAlphaTestTexture(): BaseTexture;
+        getAlphaTestTexture(): Nullable<BaseTexture>;
         isReadyForSubMesh(mesh: AbstractMesh, subMesh: SubMesh, useInstances?: boolean): boolean;
         bindForSubMesh(world: Matrix, mesh: Mesh, subMesh: SubMesh): void;
         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);
             }
             // 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
             BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, false, true);
             // Get correct effect      
@@ -140,10 +140,12 @@ var BABYLON;
                     defines: join,
                     fallbacks: fallbacks,
                     onCompiled: this.onCompiled,
-                    onError: this.onError
+                    onError: this.onError,
+                    indexParameters: null,
+                    maxSimultaneousLights: 4
                 }, engine), defines);
             }
-            if (!subMesh.effect.isReady()) {
+            if (!subMesh.effect || !subMesh.effect.isReady()) {
                 return false;
             }
             this._renderId = scene.getRenderId();
@@ -157,6 +159,9 @@ var BABYLON;
                 return;
             }
             var effect = subMesh.effect;
+            if (!effect) {
+                return;
+            }
             this._activeEffect = effect;
             // Matrices
             this.bindOnlyWorldMatrix(world);

A diferenza do arquivo foi suprimida porque é demasiado grande
+ 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;
         needAlphaBlending(): boolean;
         needAlphaTesting(): boolean;
-        getAlphaTestTexture(): BaseTexture;
+        getAlphaTestTexture(): Nullable<BaseTexture>;
         updateFur(): void;
         isReadyForSubMesh(mesh: AbstractMesh, subMesh: SubMesh, useInstances?: boolean): boolean;
         bindForSubMesh(world: Matrix, mesh: Mesh, subMesh: SubMesh): void;

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

@@ -147,7 +147,7 @@ var BABYLON;
             // Lights
             defines._needNormals = BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights, this._disableLighting);
             // 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
             BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true);
             // Get correct effect      
@@ -212,7 +212,7 @@ var BABYLON;
                     indexParameters: { maxSimultaneousLights: this.maxSimultaneousLights }
                 }, engine), defines);
             }
-            if (!subMesh.effect.isReady()) {
+            if (!subMesh.effect || !subMesh.effect.isReady()) {
                 return false;
             }
             this._renderId = scene.getRenderId();
@@ -226,6 +226,9 @@ var BABYLON;
                 return;
             }
             var effect = subMesh.effect;
+            if (!effect) {
+                return;
+            }
             this._activeEffect = effect;
             // Matrices        
             this.bindOnlyWorldMatrix(world);
@@ -312,7 +315,10 @@ var BABYLON;
             }
             if (this._meshes) {
                 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();
                 }
             }

A diferenza do arquivo foi suprimida porque é demasiado grande
+ 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);
         needAlphaBlending(): boolean;
         needAlphaTesting(): boolean;
-        getAlphaTestTexture(): BaseTexture;
+        getAlphaTestTexture(): Nullable<BaseTexture>;
         isReadyForSubMesh(mesh: AbstractMesh, subMesh: SubMesh, useInstances?: boolean): boolean;
         bindForSubMesh(world: Matrix, mesh: Mesh, subMesh: SubMesh): void;
         getAnimatables(): IAnimatable[];

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

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

A diferenza do arquivo foi suprimida porque é demasiado grande
+ 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];
                 // Defines
                 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;
             }
             this._renderId = scene.getRenderId();
@@ -132,6 +132,9 @@ var BABYLON;
                 return;
             }
             var effect = subMesh.effect;
+            if (!effect) {
+                return;
+            }
             this._activeEffect = effect;
             // Matrices
             this.bindOnlyWorldMatrix(world);

A diferenza do arquivo foi suprimida porque é demasiado grande
+ 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);
         needAlphaBlending(): boolean;
         needAlphaTesting(): boolean;
-        getAlphaTestTexture(): BaseTexture;
+        getAlphaTestTexture(): Nullable<BaseTexture>;
         isReadyForSubMesh(mesh: AbstractMesh, subMesh: SubMesh, useInstances?: boolean): boolean;
         bindForSubMesh(world: Matrix, mesh: Mesh, subMesh: SubMesh): void;
         getAnimatables(): IAnimatable[];

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

@@ -135,7 +135,7 @@ var BABYLON;
             // Lights
             defines._needNormals = BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights, this._disableLighting);
             // 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
             BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true);
             // Get correct effect      
@@ -201,7 +201,7 @@ var BABYLON;
                     indexParameters: { maxSimultaneousLights: this.maxSimultaneousLights }
                 }, engine), defines);
             }
-            if (!subMesh.effect.isReady()) {
+            if (!subMesh.effect || !subMesh.effect.isReady()) {
                 return false;
             }
             this._renderId = scene.getRenderId();
@@ -215,6 +215,9 @@ var BABYLON;
                 return;
             }
             var effect = subMesh.effect;
+            if (!effect) {
+                return;
+            }
             this._activeEffect = effect;
             // Matrices        
             this.bindOnlyWorldMatrix(world);

A diferenza do arquivo foi suprimida porque é demasiado grande
+ 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.
          * 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).
          * 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;
          * corresponding to low luminance, medium luminance, and high luminance areas respectively.
          */
-        cameraColorCurves: ColorCurves;
+        cameraColorCurves: Nullable<ColorCurves>;
         private _cameraInfos;
         private _microsurfaceTextureLods;
         /**
@@ -320,7 +320,7 @@ declare module BABYLON {
         private static _scaledEmissive;
         private static _scaledReflection;
         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;
         unbind(): 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) {
             var _this = this;
+            if (mesh === void 0) { mesh = null; }
             if (this.isFrozen) {
                 if (this._wasPreviouslyReady) {
                     return true;
@@ -474,10 +475,10 @@ var BABYLON;
             var engine = scene.getEngine();
             var needUVs = false;
             this._defines.reset();
-            if (scene.lightsEnabled && !this.disableLighting) {
+            if (scene.lightsEnabled && !this.disableLighting && mesh) {
                 BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, this._defines, true, this.maxSimultaneousLights);
             }
-            if (!this.checkReadyOnEveryCall) {
+            if (!this.checkReadyOnEveryCall && mesh) {
                 if (this._renderId === scene.getRenderId()) {
                     if (this._checkCache(scene, mesh, useInstances)) {
                         return true;
@@ -745,14 +746,14 @@ var BABYLON;
                 }
                 if (mesh.useBones && mesh.computeBonesUsingShaders) {
                     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
                 if (useInstances) {
                     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_NORMAL = manager.supportsNormals && this._defines.NORMAL;
                     this._defines.MORPHTARGETS = (manager.numInfluencers > 0);
@@ -828,9 +829,11 @@ var BABYLON;
                 if (this._defines.VERTEXCOLOR) {
                     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
                 var join = this._defines.toString();
                 var uniforms = ["world", "view", "viewProjection", "vEyePosition", "vLightsType", "vAmbientColor", "vAlbedoColor", "vReflectivityColor", "vEmissiveColor", "vReflectionColor",
@@ -882,7 +885,7 @@ var BABYLON;
                 }, engine);
                 this.buildUniformLayout();
             }
-            if (!this._effect.isReady()) {
+            if (!this._effect || !this._effect.isReady()) {
                 return false;
             }
             this._renderId = scene.getRenderId();
@@ -942,15 +945,20 @@ var BABYLON;
             _super.prototype.unbind.call(this);
         };
         LegacyPBRMaterial.prototype.bindOnlyWorldMatrix = function (world) {
-            this._effect.setMatrix("world", world);
+            if (this._effect) {
+                this._effect.setMatrix("world", world);
+            }
         };
         LegacyPBRMaterial.prototype.bind = function (world, mesh) {
             this._myScene = this.getScene();
             var effect = this._effect;
+            if (!effect) {
+                return;
+            }
             // Matrices        
             this.bindOnlyWorldMatrix(world);
             // Bones
-            BABYLON.MaterialHelper.BindBonesParameters(mesh, this._effect);
+            BABYLON.MaterialHelper.BindBonesParameters(mesh, effect);
             if (this._myScene.getCachedMaterial() !== this) {
                 this._uniformBuffer.bindToEffect(effect, "Material");
                 this.bindViewProjection(effect);
@@ -985,15 +993,17 @@ var BABYLON;
                             this._uniformBuffer.updateFloat2("vReflectionInfos", this.reflectionTexture.level, 0);
                             if (this._defines.USESPHERICALFROMREFLECTIONMAP) {
                                 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) {
@@ -1066,7 +1076,9 @@ var BABYLON;
                     this._uniformBuffer.updateColor3("vReflectionColor", LegacyPBRMaterial._scaledReflection);
                     // GAMMA CORRECTION.
                     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
                     this._lightingInfos.x = this.directIntensity;
                     this._lightingInfos.y = this.emissiveIntensity;
@@ -1144,51 +1156,51 @@ var BABYLON;
                         }
                     }
                     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 y = this.cameraColorGradingTexture.getSize().height; // Texture Size example with 8
                         var z = y - 1.0; // SizeMinusOne 8 - 1
                         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 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 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 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
-                BABYLON.MaterialHelper.BindClipPlane(this._effect, this._myScene);
+                BABYLON.MaterialHelper.BindClipPlane(effect, this._myScene);
                 // Colors
                 this._myScene.ambientColor.multiplyToRef(this.ambientColor, this._globalAmbientColor);
                 effect.setVector3("vEyePosition", this._myScene._mirroredCameraPosition ? this._myScene._mirroredCameraPosition : this._myScene.activeCamera.position);
                 effect.setColor3("vAmbientColor", this._globalAmbientColor);
             }
-            if (this._myScene.getCachedMaterial() !== this || !this.isFrozen) {
+            if (mesh && (this._myScene.getCachedMaterial() !== this || !this.isFrozen)) {
                 // Lights
                 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
                 if (this._myScene.fogEnabled && mesh.applyFog && this._myScene.fogMode !== BABYLON.Scene.FOGMODE_NONE || this.reflectionTexture) {
                     this.bindView(effect);
                 }
                 // Fog
-                BABYLON.MaterialHelper.BindFogParameters(this._myScene, mesh, this._effect);
+                BABYLON.MaterialHelper.BindFogParameters(this._myScene, mesh, effect);
                 // Morph targets
                 if (this._defines.NUM_MORPH_INFLUENCERS) {
-                    BABYLON.MaterialHelper.BindMorphTargetParameters(mesh, this._effect);
+                    BABYLON.MaterialHelper.BindMorphTargetParameters(mesh, effect);
                 }
                 this._cameraInfos.x = this.cameraExposure;
                 this._cameraInfos.y = this.cameraContrast;
                 effect.setVector4("vCameraInfos", this._cameraInfos);
                 if (this.cameraColorCurves) {
-                    BABYLON.ColorCurves.Bind(this.cameraColorCurves, this._effect);
+                    BABYLON.ColorCurves.Bind(this.cameraColorCurves, effect);
                 }
                 // Log. depth
-                BABYLON.MaterialHelper.BindLogDepth(this._defines, this._effect, this._myScene);
+                BABYLON.MaterialHelper.BindLogDepth(this._defines, effect, this._myScene);
             }
             this._uniformBuffer.update();
             this._afterBind(mesh);

A diferenza do arquivo foi suprimida porque é demasiado grande
+ 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);
         needAlphaBlending(): boolean;
         needAlphaTesting(): boolean;
-        getAlphaTestTexture(): BaseTexture;
+        getAlphaTestTexture(): Nullable<BaseTexture>;
         isReadyForSubMesh(mesh: AbstractMesh, subMesh: SubMesh, useInstances?: boolean): boolean;
         bindForSubMesh(world: Matrix, mesh: Mesh, subMesh: SubMesh): void;
         getAnimatables(): IAnimatable[];

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

@@ -129,7 +129,7 @@ var BABYLON;
             // Lights
             defines._needNormals = BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights, this._disableLighting);
             // 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
             BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true);
             // Get correct effect      
@@ -190,7 +190,7 @@ var BABYLON;
                     indexParameters: { maxSimultaneousLights: 4 }
                 }, engine), defines);
             }
-            if (!subMesh.effect.isReady()) {
+            if (!subMesh.effect || !subMesh.effect.isReady()) {
                 return false;
             }
             this._renderId = scene.getRenderId();
@@ -204,6 +204,9 @@ var BABYLON;
                 return;
             }
             var effect = subMesh.effect;
+            if (!effect) {
+                return;
+            }
             this._activeEffect = effect;
             // Matrices        
             this.bindOnlyWorldMatrix(world);

A diferenza do arquivo foi suprimida porque é demasiado grande
+ 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);
         needAlphaBlending(): boolean;
         needAlphaTesting(): boolean;
-        getAlphaTestTexture(): BaseTexture;
+        getAlphaTestTexture(): Nullable<BaseTexture>;
         activeLight: IShadowLight;
         isReadyForSubMesh(mesh: AbstractMesh, subMesh: SubMesh, useInstances?: boolean): boolean;
         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);
             defines._needNormals = BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, 1);
             // Attribs
@@ -139,7 +139,7 @@ var BABYLON;
                     indexParameters: { maxSimultaneousLights: 1 }
                 }, engine), defines);
             }
-            if (!subMesh.effect.isReady()) {
+            if (!subMesh.effect || !subMesh.effect.isReady()) {
                 return false;
             }
             this._renderId = scene.getRenderId();
@@ -153,6 +153,9 @@ var BABYLON;
                 return;
             }
             var effect = subMesh.effect;
+            if (!effect) {
+                return;
+            }
             this._activeEffect = effect;
             // Matrices        
             this.bindOnlyWorldMatrix(world);

A diferenza do arquivo foi suprimida porque é demasiado grande
+ 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);
         needAlphaBlending(): boolean;
         needAlphaTesting(): boolean;
-        getAlphaTestTexture(): BaseTexture;
+        getAlphaTestTexture(): Nullable<BaseTexture>;
         isReadyForSubMesh(mesh: AbstractMesh, subMesh: SubMesh, useInstances?: boolean): boolean;
         bindForSubMesh(world: Matrix, mesh: Mesh, subMesh: SubMesh): void;
         getAnimatables(): IAnimatable[];

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

@@ -96,7 +96,7 @@ var BABYLON;
             // Lights
             defines._needNormals = BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights, this._disableLighting);
             // 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
             BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true);
             // Get correct effect      
@@ -157,7 +157,7 @@ var BABYLON;
                     indexParameters: { maxSimultaneousLights: this._maxSimultaneousLights - 1 }
                 }, engine), defines);
             }
-            if (!subMesh.effect.isReady()) {
+            if (!subMesh.effect || !subMesh.effect.isReady()) {
                 return false;
             }
             this._renderId = scene.getRenderId();
@@ -171,6 +171,9 @@ var BABYLON;
                 return;
             }
             var effect = subMesh.effect;
+            if (!effect) {
+                return;
+            }
             this._activeEffect = effect;
             // Matrices        
             this.bindOnlyWorldMatrix(world);

A diferenza do arquivo foi suprimida porque é demasiado grande
+ 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);
         needAlphaBlending(): boolean;
         needAlphaTesting(): boolean;
-        getAlphaTestTexture(): BaseTexture;
+        getAlphaTestTexture(): Nullable<BaseTexture>;
         isReadyForSubMesh(mesh: AbstractMesh, subMesh: SubMesh, useInstances?: boolean): boolean;
         bindForSubMesh(world: Matrix, mesh: Mesh, subMesh: SubMesh): void;
         getAnimatables(): IAnimatable[];

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

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

A diferenza do arquivo foi suprimida porque é demasiado grande
+ 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);
         needAlphaBlending(): boolean;
         needAlphaTesting(): boolean;
-        getAlphaTestTexture(): BaseTexture;
+        getAlphaTestTexture(): Nullable<BaseTexture>;
         isReadyForSubMesh(mesh: AbstractMesh, subMesh: SubMesh, useInstances?: boolean): boolean;
         bindForSubMesh(world: Matrix, mesh: Mesh, subMesh: SubMesh): void;
         getAnimatables(): IAnimatable[];

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

@@ -102,7 +102,7 @@ var BABYLON;
             // Lights
             defines._needNormals = BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights, this._disableLighting);
             // 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
             BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true);
             // Get correct effect      
@@ -167,7 +167,7 @@ var BABYLON;
                     indexParameters: { maxSimultaneousLights: this.maxSimultaneousLights }
                 }, engine), defines);
             }
-            if (!subMesh.effect.isReady()) {
+            if (!subMesh.effect || !subMesh.effect.isReady()) {
                 return false;
             }
             this._renderId = scene.getRenderId();
@@ -181,6 +181,9 @@ var BABYLON;
                 return;
             }
             var effect = subMesh.effect;
+            if (!effect) {
+                return;
+            }
             this._activeEffect = effect;
             // Matrices        
             this.bindOnlyWorldMatrix(world);

A diferenza do arquivo foi suprimida porque é demasiado grande
+ 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);
         needAlphaBlending(): boolean;
         needAlphaTesting(): boolean;
-        getAlphaTestTexture(): BaseTexture;
+        getAlphaTestTexture(): Nullable<BaseTexture>;
         isReadyForSubMesh(mesh: AbstractMesh, subMesh: SubMesh, useInstances?: boolean): boolean;
         bindForSubMesh(world: Matrix, mesh: Mesh, subMesh: SubMesh): void;
         getAnimatables(): IAnimatable[];

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

@@ -121,7 +121,7 @@ var BABYLON;
             // Lights
             defines._needNormals = BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights, this._disableLighting);
             // 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
             BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true);
             // Get correct effect      
@@ -179,7 +179,7 @@ var BABYLON;
                     indexParameters: { maxSimultaneousLights: this.maxSimultaneousLights }
                 }, engine), defines);
             }
-            if (!subMesh.effect.isReady()) {
+            if (!subMesh.effect || !subMesh.effect.isReady()) {
                 return false;
             }
             this._renderId = scene.getRenderId();
@@ -193,6 +193,9 @@ var BABYLON;
                 return;
             }
             var effect = subMesh.effect;
+            if (!effect) {
+                return;
+            }
             this._activeEffect = effect;
             // Matrices        
             this.bindOnlyWorldMatrix(world);

A diferenza do arquivo foi suprimida porque é demasiado grande
+ 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;
         addToRenderList(node: any): void;
         enableRenderTargets(enable: boolean): void;
-        getRenderList(): AbstractMesh[];
+        getRenderList(): Nullable<AbstractMesh[]>;
         readonly renderTargetsEnabled: boolean;
         needAlphaBlending(): boolean;
         needAlphaTesting(): boolean;
-        getAlphaTestTexture(): BaseTexture;
+        getAlphaTestTexture(): Nullable<BaseTexture>;
         isReadyForSubMesh(mesh: AbstractMesh, subMesh: SubMesh, useInstances?: boolean): boolean;
         bindForSubMesh(world: Matrix, mesh: Mesh, subMesh: SubMesh): void;
         private _createRenderTargets(scene, renderTargetSize);

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

@@ -158,8 +158,12 @@ var BABYLON;
         });
         // Methods
         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) {
             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);
             if (defines._areMiscDirty) {
                 if (this._fresnelSeparate) {
@@ -307,7 +311,7 @@ var BABYLON;
                     indexParameters: { maxSimultaneousLights: this._maxSimultaneousLights }
                 }, engine), defines);
             }
-            if (!subMesh.effect.isReady()) {
+            if (!subMesh.effect || !subMesh.effect.isReady()) {
                 return false;
             }
             this._renderId = scene.getRenderId();
@@ -321,6 +325,9 @@ var BABYLON;
                 return;
             }
             var effect = subMesh.effect;
+            if (!effect || !this._mesh) {
+                return;
+            }
             this._activeEffect = effect;
             // Matrices        
             this.bindOnlyWorldMatrix(world);

A diferenza do arquivo foi suprimida porque é demasiado grande
+ 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);
             defines._needNormals = BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, 1);
             // Attribs
@@ -148,7 +148,7 @@ var BABYLON;
                     indexParameters: { maxSimultaneousLights: 1 }
                 }, engine), defines);
             }
-            if (!subMesh.effect.isReady()) {
+            if (!subMesh.effect || !subMesh.effect.isReady()) {
                 return false;
             }
             this._renderId = scene.getRenderId();
@@ -162,6 +162,9 @@ var BABYLON;
                 return;
             }
             var effect = subMesh.effect;
+            if (!effect) {
+                return;
+            }
             this._activeEffect = effect;
             // Matrices        
             this.bindOnlyWorldMatrix(world);
@@ -322,7 +325,7 @@ var BABYLON;
                 }
             }
             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);
             defines._needNormals = BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights);
             // Attribs
@@ -387,7 +390,7 @@ var BABYLON;
                     indexParameters: { maxSimultaneousLights: 4 }
                 }, engine), defines);
             }
-            if (!subMesh.effect.isReady()) {
+            if (!subMesh.effect || !subMesh.effect.isReady()) {
                 return false;
             }
             this._renderId = scene.getRenderId();
@@ -401,15 +404,18 @@ var BABYLON;
                 return;
             }
             var effect = subMesh.effect;
+            if (!effect) {
+                return;
+            }
             this._activeEffect = effect;
             // Matrices        
             this.bindOnlyWorldMatrix(world);
             this._activeEffect.setMatrix("viewProjection", scene.getTransformMatrix());
             // Bones
-            BABYLON.MaterialHelper.BindBonesParameters(mesh, this._effect);
+            BABYLON.MaterialHelper.BindBonesParameters(mesh, effect);
             if (this._mustRebind(scene, effect)) {
                 // Clip plane
-                BABYLON.MaterialHelper.BindClipPlane(this._effect, scene);
+                BABYLON.MaterialHelper.BindClipPlane(effect, scene);
                 // Point size
                 if (this.pointsCloud) {
                     this._activeEffect.setFloat("pointSize", this.pointSize);
@@ -608,7 +614,7 @@ var BABYLON;
             // Lights
             defines._needNormals = BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights, this._disableLighting);
             // 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
             BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true);
             // Get correct effect      
@@ -669,7 +675,7 @@ var BABYLON;
                     indexParameters: { maxSimultaneousLights: 4 }
                 }, engine), defines);
             }
-            if (!subMesh.effect.isReady()) {
+            if (!subMesh.effect || !subMesh.effect.isReady()) {
                 return false;
             }
             this._renderId = scene.getRenderId();
@@ -683,6 +689,9 @@ var BABYLON;
                 return;
             }
             var effect = subMesh.effect;
+            if (!effect) {
+                return;
+            }
             this._activeEffect = effect;
             // Matrices        
             this.bindOnlyWorldMatrix(world);
@@ -916,7 +925,7 @@ var BABYLON;
             // Lights
             defines._needNormals = BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights, this._disableLighting);
             // 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
             BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true);
             // Get correct effect      
@@ -982,7 +991,7 @@ var BABYLON;
                     indexParameters: { maxSimultaneousLights: this.maxSimultaneousLights }
                 }, engine), defines);
             }
-            if (!subMesh.effect.isReady()) {
+            if (!subMesh.effect || !subMesh.effect.isReady()) {
                 return false;
             }
             this._renderId = scene.getRenderId();
@@ -996,6 +1005,9 @@ var BABYLON;
                 return;
             }
             var effect = subMesh.effect;
+            if (!effect) {
+                return;
+            }
             this._activeEffect = effect;
             // Matrices        
             this.bindOnlyWorldMatrix(world);
@@ -1225,7 +1237,7 @@ var BABYLON;
             // Lights
             defines._needNormals = BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights, this._disableLighting);
             // 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
             BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true);
             // Get correct effect      
@@ -1286,7 +1298,7 @@ var BABYLON;
                     indexParameters: { maxSimultaneousLights: this._maxSimultaneousLights - 1 }
                 }, engine), defines);
             }
-            if (!subMesh.effect.isReady()) {
+            if (!subMesh.effect || !subMesh.effect.isReady()) {
                 return false;
             }
             this._renderId = scene.getRenderId();
@@ -1300,6 +1312,9 @@ var BABYLON;
                 return;
             }
             var effect = subMesh.effect;
+            if (!effect) {
+                return;
+            }
             this._activeEffect = effect;
             // Matrices        
             this.bindOnlyWorldMatrix(world);
@@ -1556,8 +1571,12 @@ var BABYLON;
         });
         // Methods
         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) {
             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);
             if (defines._areMiscDirty) {
                 if (this._fresnelSeparate) {
@@ -1705,7 +1724,7 @@ var BABYLON;
                     indexParameters: { maxSimultaneousLights: this._maxSimultaneousLights }
                 }, engine), defines);
             }
-            if (!subMesh.effect.isReady()) {
+            if (!subMesh.effect || !subMesh.effect.isReady()) {
                 return false;
             }
             this._renderId = scene.getRenderId();
@@ -1719,6 +1738,9 @@ var BABYLON;
                 return;
             }
             var effect = subMesh.effect;
+            if (!effect || !this._mesh) {
+                return;
+            }
             this._activeEffect = effect;
             // Matrices        
             this.bindOnlyWorldMatrix(world);
@@ -2084,7 +2106,7 @@ var BABYLON;
                 defines.FOG = (scene.fogEnabled && mesh.applyFog && scene.fogMode !== BABYLON.Scene.FOGMODE_NONE && this.fogEnabled);
             }
             // 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
             BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, false, true);
             // Get correct effect      
@@ -2130,10 +2152,12 @@ var BABYLON;
                     defines: join,
                     fallbacks: fallbacks,
                     onCompiled: this.onCompiled,
-                    onError: this.onError
+                    onError: this.onError,
+                    indexParameters: null,
+                    maxSimultaneousLights: 4
                 }, engine), defines);
             }
-            if (!subMesh.effect.isReady()) {
+            if (!subMesh.effect || !subMesh.effect.isReady()) {
                 return false;
             }
             this._renderId = scene.getRenderId();
@@ -2147,6 +2171,9 @@ var BABYLON;
                 return;
             }
             var effect = subMesh.effect;
+            if (!effect) {
+                return;
+            }
             this._activeEffect = effect;
             // Matrices
             this.bindOnlyWorldMatrix(world);
@@ -2452,7 +2479,7 @@ var BABYLON;
             // Lights
             defines._needNormals = BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights, this._disableLighting);
             // 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
             BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true);
             // Get correct effect      
@@ -2517,7 +2544,7 @@ var BABYLON;
                     indexParameters: { maxSimultaneousLights: this.maxSimultaneousLights }
                 }, engine), defines);
             }
-            if (!subMesh.effect.isReady()) {
+            if (!subMesh.effect || !subMesh.effect.isReady()) {
                 return false;
             }
             this._renderId = scene.getRenderId();
@@ -2531,6 +2558,9 @@ var BABYLON;
                 return;
             }
             var effect = subMesh.effect;
+            if (!effect) {
+                return;
+            }
             this._activeEffect = effect;
             // Matrices        
             this.bindOnlyWorldMatrix(world);
@@ -2617,7 +2647,10 @@ var BABYLON;
             }
             if (this._meshes) {
                 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();
                 }
             }
@@ -2863,7 +2896,7 @@ var BABYLON;
             // Lights
             defines._needNormals = BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights, this._disableLighting);
             // 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
             BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true);
             // Get correct effect      
@@ -2928,7 +2961,7 @@ var BABYLON;
                     indexParameters: { maxSimultaneousLights: this.maxSimultaneousLights }
                 }, engine), defines);
             }
-            if (!subMesh.effect.isReady()) {
+            if (!subMesh.effect || !subMesh.effect.isReady()) {
                 return false;
             }
             this._renderId = scene.getRenderId();
@@ -2942,6 +2975,9 @@ var BABYLON;
                 return;
             }
             var effect = subMesh.effect;
+            if (!effect) {
+                return;
+            }
             this._activeEffect = effect;
             // Matrices        
             this.bindOnlyWorldMatrix(world);
@@ -3266,7 +3302,7 @@ var BABYLON;
             // Lights
             defines._needNormals = BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights, this._disableLighting);
             // 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
             BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true);
             // Get correct effect      
@@ -3324,7 +3360,7 @@ var BABYLON;
                     indexParameters: { maxSimultaneousLights: this.maxSimultaneousLights }
                 }, engine), defines);
             }
-            if (!subMesh.effect.isReady()) {
+            if (!subMesh.effect || !subMesh.effect.isReady()) {
                 return false;
             }
             this._renderId = scene.getRenderId();
@@ -3338,6 +3374,9 @@ var BABYLON;
                 return;
             }
             var effect = subMesh.effect;
+            if (!effect) {
+                return;
+            }
             this._activeEffect = effect;
             // Matrices        
             this.bindOnlyWorldMatrix(world);
@@ -3625,7 +3664,7 @@ var BABYLON;
                     "cameraPosition"
                 ], [], join, fallbacks, this.onCompiled, this.onError), defines);
             }
-            if (!subMesh.effect.isReady()) {
+            if (!subMesh.effect || !subMesh.effect.isReady()) {
                 return false;
             }
             this._renderId = scene.getRenderId();
@@ -3639,6 +3678,9 @@ var BABYLON;
                 return;
             }
             var effect = subMesh.effect;
+            if (!effect) {
+                return;
+            }
             this._activeEffect = effect;
             // Matrices        
             this.bindOnlyWorldMatrix(world);
@@ -3852,9 +3894,9 @@ var BABYLON;
                 var attribs = [BABYLON.VertexBuffer.PositionKind, BABYLON.VertexBuffer.NormalKind];
                 // Defines
                 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;
             }
             this._renderId = scene.getRenderId();
@@ -3868,6 +3910,9 @@ var BABYLON;
                 return;
             }
             var effect = subMesh.effect;
+            if (!effect) {
+                return;
+            }
             this._activeEffect = effect;
             // Matrices
             this.bindOnlyWorldMatrix(world);
@@ -4493,7 +4538,7 @@ var BABYLON;
             // Attribs
             BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true, true);
             // 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      
             if (defines.isDirty) {
                 defines.markAsProcessed();
@@ -4600,7 +4645,7 @@ var BABYLON;
                 }, engine), defines);
                 this.buildUniformLayout();
             }
-            if (!subMesh.effect.isReady()) {
+            if (!subMesh.effect || !subMesh.effect.isReady()) {
                 return false;
             }
             defines._renderId = scene.getRenderId();
@@ -4661,6 +4706,9 @@ var BABYLON;
                 return;
             }
             var effect = subMesh.effect;
+            if (!effect) {
+                return;
+            }
             this._activeEffect = effect;
             // Matrices        
             this.bindOnlyWorldMatrix(world);
@@ -5880,11 +5928,14 @@ vColor=color;\n\
                 return this._createdShaderName;
             this._isCreatedShader = false;
             CustomMaterial.ShaderIndexer++;
-            var name = name + "custom_" + CustomMaterial.ShaderIndexer;
+            var name = "custom_" + CustomMaterial.ShaderIndexer;
             this.ReviewUniform("uniform", uniforms);
             this.ReviewUniform("sampler", samplers);
             var fn_afterBind = this._afterBind;
             this._afterBind = function (m, e) {
+                if (!e) {
+                    return;
+                }
                 _this.AttachAfterBind(m, e);
                 try {
                     fn_afterBind(m, e);
@@ -6077,7 +6128,7 @@ var BABYLON;
             // Lights
             defines._needNormals = BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights, this._disableLighting);
             // 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
             BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true);
             // Get correct effect      
@@ -6138,7 +6189,7 @@ var BABYLON;
                     indexParameters: { maxSimultaneousLights: this.maxSimultaneousLights - 1 }
                 }, engine), defines);
             }
-            if (!subMesh.effect.isReady()) {
+            if (!subMesh.effect || !subMesh.effect.isReady()) {
                 return false;
             }
             this._renderId = scene.getRenderId();
@@ -6152,6 +6203,9 @@ var BABYLON;
                 return;
             }
             var effect = subMesh.effect;
+            if (!effect) {
+                return;
+            }
             this._activeEffect = effect;
             // Matrices        
             this.bindOnlyWorldMatrix(world);
@@ -6718,6 +6772,7 @@ var BABYLON;
         };
         LegacyPBRMaterial.prototype.isReady = function (mesh, useInstances) {
             var _this = this;
+            if (mesh === void 0) { mesh = null; }
             if (this.isFrozen) {
                 if (this._wasPreviouslyReady) {
                     return true;
@@ -6727,10 +6782,10 @@ var BABYLON;
             var engine = scene.getEngine();
             var needUVs = false;
             this._defines.reset();
-            if (scene.lightsEnabled && !this.disableLighting) {
+            if (scene.lightsEnabled && !this.disableLighting && mesh) {
                 BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, this._defines, true, this.maxSimultaneousLights);
             }
-            if (!this.checkReadyOnEveryCall) {
+            if (!this.checkReadyOnEveryCall && mesh) {
                 if (this._renderId === scene.getRenderId()) {
                     if (this._checkCache(scene, mesh, useInstances)) {
                         return true;
@@ -6998,14 +7053,14 @@ var BABYLON;
                 }
                 if (mesh.useBones && mesh.computeBonesUsingShaders) {
                     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
                 if (useInstances) {
                     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_NORMAL = manager.supportsNormals && this._defines.NORMAL;
                     this._defines.MORPHTARGETS = (manager.numInfluencers > 0);
@@ -7081,9 +7136,11 @@ var BABYLON;
                 if (this._defines.VERTEXCOLOR) {
                     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
                 var join = this._defines.toString();
                 var uniforms = ["world", "view", "viewProjection", "vEyePosition", "vLightsType", "vAmbientColor", "vAlbedoColor", "vReflectivityColor", "vEmissiveColor", "vReflectionColor",
@@ -7135,7 +7192,7 @@ var BABYLON;
                 }, engine);
                 this.buildUniformLayout();
             }
-            if (!this._effect.isReady()) {
+            if (!this._effect || !this._effect.isReady()) {
                 return false;
             }
             this._renderId = scene.getRenderId();
@@ -7195,15 +7252,20 @@ var BABYLON;
             _super.prototype.unbind.call(this);
         };
         LegacyPBRMaterial.prototype.bindOnlyWorldMatrix = function (world) {
-            this._effect.setMatrix("world", world);
+            if (this._effect) {
+                this._effect.setMatrix("world", world);
+            }
         };
         LegacyPBRMaterial.prototype.bind = function (world, mesh) {
             this._myScene = this.getScene();
             var effect = this._effect;
+            if (!effect) {
+                return;
+            }
             // Matrices        
             this.bindOnlyWorldMatrix(world);
             // Bones
-            BABYLON.MaterialHelper.BindBonesParameters(mesh, this._effect);
+            BABYLON.MaterialHelper.BindBonesParameters(mesh, effect);
             if (this._myScene.getCachedMaterial() !== this) {
                 this._uniformBuffer.bindToEffect(effect, "Material");
                 this.bindViewProjection(effect);
@@ -7238,15 +7300,17 @@ var BABYLON;
                             this._uniformBuffer.updateFloat2("vReflectionInfos", this.reflectionTexture.level, 0);
                             if (this._defines.USESPHERICALFROMREFLECTIONMAP) {
                                 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) {
@@ -7319,7 +7383,9 @@ var BABYLON;
                     this._uniformBuffer.updateColor3("vReflectionColor", LegacyPBRMaterial._scaledReflection);
                     // GAMMA CORRECTION.
                     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
                     this._lightingInfos.x = this.directIntensity;
                     this._lightingInfos.y = this.emissiveIntensity;
@@ -7397,51 +7463,51 @@ var BABYLON;
                         }
                     }
                     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 y = this.cameraColorGradingTexture.getSize().height; // Texture Size example with 8
                         var z = y - 1.0; // SizeMinusOne 8 - 1
                         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 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 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 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
-                BABYLON.MaterialHelper.BindClipPlane(this._effect, this._myScene);
+                BABYLON.MaterialHelper.BindClipPlane(effect, this._myScene);
                 // Colors
                 this._myScene.ambientColor.multiplyToRef(this.ambientColor, this._globalAmbientColor);
                 effect.setVector3("vEyePosition", this._myScene._mirroredCameraPosition ? this._myScene._mirroredCameraPosition : this._myScene.activeCamera.position);
                 effect.setColor3("vAmbientColor", this._globalAmbientColor);
             }
-            if (this._myScene.getCachedMaterial() !== this || !this.isFrozen) {
+            if (mesh && (this._myScene.getCachedMaterial() !== this || !this.isFrozen)) {
                 // Lights
                 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
                 if (this._myScene.fogEnabled && mesh.applyFog && this._myScene.fogMode !== BABYLON.Scene.FOGMODE_NONE || this.reflectionTexture) {
                     this.bindView(effect);
                 }
                 // Fog
-                BABYLON.MaterialHelper.BindFogParameters(this._myScene, mesh, this._effect);
+                BABYLON.MaterialHelper.BindFogParameters(this._myScene, mesh, effect);
                 // Morph targets
                 if (this._defines.NUM_MORPH_INFLUENCERS) {
-                    BABYLON.MaterialHelper.BindMorphTargetParameters(mesh, this._effect);
+                    BABYLON.MaterialHelper.BindMorphTargetParameters(mesh, effect);
                 }
                 this._cameraInfos.x = this.cameraExposure;
                 this._cameraInfos.y = this.cameraContrast;
                 effect.setVector4("vCameraInfos", this._cameraInfos);
                 if (this.cameraColorCurves) {
-                    BABYLON.ColorCurves.Bind(this.cameraColorCurves, this._effect);
+                    BABYLON.ColorCurves.Bind(this.cameraColorCurves, effect);
                 }
                 // Log. depth
-                BABYLON.MaterialHelper.BindLogDepth(this._defines, this._effect, this._myScene);
+                BABYLON.MaterialHelper.BindLogDepth(this._defines, effect, this._myScene);
             }
             this._uniformBuffer.update();
             this._afterBind(mesh);
@@ -8066,7 +8132,7 @@ var BABYLON;
              * Sets the Color Grading 2D Lookup Texture.
              */
             set: function (value) {
-                this._imageProcessingConfiguration.colorGradingTexture = value;
+                this.imageProcessingConfiguration.colorGradingTexture = value;
             },
             enumerable: true,
             configurable: true
@@ -8079,7 +8145,7 @@ var BABYLON;
              * corresponding to low luminance, medium luminance, and high luminance areas respectively.
              */
             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).
@@ -8088,7 +8154,7 @@ var BABYLON;
              * corresponding to low luminance, medium luminance, and high luminance areas respectively.
              */
             set: function (value) {
-                this._imageProcessingConfiguration.colorCurves = value;
+                this.imageProcessingConfiguration.colorCurves = value;
             },
             enumerable: true,
             configurable: true
@@ -8269,7 +8335,7 @@ var BABYLON;
                 }, engine), defines);
                 this.buildUniformLayout();
             }
-            if (!subMesh.effect.isReady()) {
+            if (!subMesh.effect || !subMesh.effect.isReady()) {
                 return false;
             }
             defines._renderId = scene.getRenderId();
@@ -8324,6 +8390,9 @@ var BABYLON;
                 return;
             }
             var effect = subMesh.effect;
+            if (!effect) {
+                return;
+            }
             this._activeEffect = effect;
             // Matrices
             this.bindOnlyWorldMatrix(world);
@@ -8396,7 +8465,6 @@ var BABYLON;
             }
             this._uniformBuffer.update();
             this._afterBind(mesh);
-            scene = null;
         };
         /**
          * Dispose the material.

A diferenza do arquivo foi suprimida porque é demasiado grande
+ 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);
         needAlphaBlending(): boolean;
         needAlphaTesting(): boolean;
-        getAlphaTestTexture(): BaseTexture;
+        getAlphaTestTexture(): Nullable<BaseTexture>;
         activeLight: IShadowLight;
         isReadyForSubMesh(mesh: AbstractMesh, subMesh: SubMesh, useInstances?: boolean): boolean;
         bindForSubMesh(world: Matrix, mesh: Mesh, subMesh: SubMesh): void;
@@ -39,7 +39,7 @@ declare module BABYLON {
         constructor(name: string, scene: Scene);
         needAlphaBlending(): boolean;
         needAlphaTesting(): boolean;
-        getAlphaTestTexture(): BaseTexture;
+        getAlphaTestTexture(): Nullable<BaseTexture>;
         isReadyForSubMesh(mesh: AbstractMesh, subMesh: SubMesh, useInstances?: boolean): boolean;
         bindForSubMesh(world: Matrix, mesh: Mesh, subMesh: SubMesh): void;
         getAnimatables(): IAnimatable[];
@@ -65,7 +65,7 @@ declare module BABYLON {
         constructor(name: string, scene: Scene);
         needAlphaBlending(): boolean;
         needAlphaTesting(): boolean;
-        getAlphaTestTexture(): BaseTexture;
+        getAlphaTestTexture(): Nullable<BaseTexture>;
         isReadyForSubMesh(mesh: AbstractMesh, subMesh: SubMesh, useInstances?: boolean): boolean;
         bindForSubMesh(world: Matrix, mesh: Mesh, subMesh: SubMesh): void;
         getAnimatables(): IAnimatable[];
@@ -101,7 +101,7 @@ declare module BABYLON {
         constructor(name: string, scene: Scene);
         needAlphaBlending(): boolean;
         needAlphaTesting(): boolean;
-        getAlphaTestTexture(): BaseTexture;
+        getAlphaTestTexture(): Nullable<BaseTexture>;
         isReadyForSubMesh(mesh: AbstractMesh, subMesh: SubMesh, useInstances?: boolean): boolean;
         bindForSubMesh(world: Matrix, mesh: Mesh, subMesh: SubMesh): void;
         getAnimatables(): IAnimatable[];
@@ -129,7 +129,7 @@ declare module BABYLON {
         constructor(name: string, scene: Scene);
         needAlphaBlending(): boolean;
         needAlphaTesting(): boolean;
-        getAlphaTestTexture(): BaseTexture;
+        getAlphaTestTexture(): Nullable<BaseTexture>;
         isReadyForSubMesh(mesh: AbstractMesh, subMesh: SubMesh, useInstances?: boolean): boolean;
         bindForSubMesh(world: Matrix, mesh: Mesh, subMesh: SubMesh): void;
         getAnimatables(): IAnimatable[];
@@ -229,11 +229,11 @@ declare module BABYLON {
         readonly reflectionTexture: RenderTargetTexture;
         addToRenderList(node: any): void;
         enableRenderTargets(enable: boolean): void;
-        getRenderList(): AbstractMesh[];
+        getRenderList(): Nullable<AbstractMesh[]>;
         readonly renderTargetsEnabled: boolean;
         needAlphaBlending(): boolean;
         needAlphaTesting(): boolean;
-        getAlphaTestTexture(): BaseTexture;
+        getAlphaTestTexture(): Nullable<BaseTexture>;
         isReadyForSubMesh(mesh: AbstractMesh, subMesh: SubMesh, useInstances?: boolean): boolean;
         bindForSubMesh(world: Matrix, mesh: Mesh, subMesh: SubMesh): void;
         private _createRenderTargets(scene, renderTargetSize);
@@ -253,11 +253,11 @@ declare module BABYLON {
 declare module BABYLON {
     class FireMaterial extends PushMaterial {
         private _diffuseTexture;
-        diffuseTexture: BaseTexture;
+        diffuseTexture: Nullable<BaseTexture>;
         private _distortionTexture;
-        distortionTexture: BaseTexture;
+        distortionTexture: Nullable<BaseTexture>;
         private _opacityTexture;
-        opacityTexture: BaseTexture;
+        opacityTexture: Nullable<BaseTexture>;
         diffuseColor: Color3;
         speed: number;
         private _scaledDiffuse;
@@ -266,7 +266,7 @@ declare module BABYLON {
         constructor(name: string, scene: Scene);
         needAlphaBlending(): boolean;
         needAlphaTesting(): boolean;
-        getAlphaTestTexture(): BaseTexture;
+        getAlphaTestTexture(): Nullable<BaseTexture>;
         isReadyForSubMesh(mesh: AbstractMesh, subMesh: SubMesh, useInstances?: boolean): boolean;
         bindForSubMesh(world: Matrix, mesh: Mesh, subMesh: SubMesh): void;
         getAnimatables(): IAnimatable[];
@@ -309,7 +309,7 @@ declare module BABYLON {
         furTime: number;
         needAlphaBlending(): boolean;
         needAlphaTesting(): boolean;
-        getAlphaTestTexture(): BaseTexture;
+        getAlphaTestTexture(): Nullable<BaseTexture>;
         updateFur(): void;
         isReadyForSubMesh(mesh: AbstractMesh, subMesh: SubMesh, useInstances?: boolean): boolean;
         bindForSubMesh(world: Matrix, mesh: Mesh, subMesh: SubMesh): void;
@@ -354,7 +354,7 @@ declare module BABYLON {
         constructor(name: string, scene: Scene);
         needAlphaBlending(): boolean;
         needAlphaTesting(): boolean;
-        getAlphaTestTexture(): BaseTexture;
+        getAlphaTestTexture(): Nullable<BaseTexture>;
         isReadyForSubMesh(mesh: AbstractMesh, subMesh: SubMesh, useInstances?: boolean): boolean;
         bindForSubMesh(world: Matrix, mesh: Mesh, subMesh: SubMesh): void;
         getAnimatables(): IAnimatable[];
@@ -396,7 +396,7 @@ declare module BABYLON {
         constructor(name: string, scene: Scene);
         needAlphaBlending(): boolean;
         needAlphaTesting(): boolean;
-        getAlphaTestTexture(): BaseTexture;
+        getAlphaTestTexture(): Nullable<BaseTexture>;
         isReadyForSubMesh(mesh: AbstractMesh, subMesh: SubMesh, useInstances?: boolean): boolean;
         bindForSubMesh(world: Matrix, mesh: Mesh, subMesh: SubMesh): void;
         getAnimatables(): IAnimatable[];
@@ -428,7 +428,7 @@ declare module BABYLON {
         constructor(name: string, scene: Scene);
         needAlphaBlending(): boolean;
         needAlphaTesting(): boolean;
-        getAlphaTestTexture(): BaseTexture;
+        getAlphaTestTexture(): Nullable<BaseTexture>;
         isReadyForSubMesh(mesh: AbstractMesh, subMesh: SubMesh, useInstances?: boolean): boolean;
         bindForSubMesh(world: Matrix, mesh: Mesh, subMesh: SubMesh): void;
         getAnimatables(): IAnimatable[];
@@ -678,7 +678,7 @@ declare module BABYLON {
          * Attaches a new image processing configuration to the Standard Material.
          * @param configuration
          */
-        protected _attachImageProcessingConfiguration(configuration: ImageProcessingConfiguration): void;
+        protected _attachImageProcessingConfiguration(configuration: Nullable<ImageProcessingConfiguration>): void;
         /**
          * Gets wether the color curves effect is enabled.
          */
@@ -724,7 +724,7 @@ declare module BABYLON {
         /**
          * 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;
         protected _renderTargets: SmartArray<RenderTargetTexture>;
         protected _worldViewProjectionMatrix: Matrix;
@@ -844,7 +844,7 @@ declare module BABYLON {
         constructor(name: string, scene: Scene);
         needAlphaBlending(): boolean;
         needAlphaTesting(): boolean;
-        getAlphaTestTexture(): BaseTexture;
+        getAlphaTestTexture(): Nullable<BaseTexture>;
         isReadyForSubMesh(mesh: AbstractMesh, subMesh: SubMesh, useInstances?: boolean): boolean;
         bindForSubMesh(world: Matrix, mesh: Mesh, subMesh: SubMesh): void;
         getAnimatables(): IAnimatable[];
@@ -919,14 +919,14 @@ declare module BABYLON {
          * Color Grading 2D Lookup Texture.
          * 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).
          * 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;
          * corresponding to low luminance, medium luminance, and high luminance areas respectively.
          */
-        cameraColorCurves: ColorCurves;
+        cameraColorCurves: Nullable<ColorCurves>;
         private _cameraInfos;
         private _microsurfaceTextureLods;
         /**
@@ -1180,7 +1180,7 @@ declare module BABYLON {
         private static _scaledEmissive;
         private static _scaledReflection;
         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;
         unbind(): void;
         bindOnlyWorldMatrix(world: Matrix): void;
@@ -1304,7 +1304,7 @@ declare namespace BABYLON {
          *
          * If sets to null, the scene one is in use.
          */
-        imageProcessingConfiguration: ImageProcessingConfiguration;
+        imageProcessingConfiguration: Nullable<ImageProcessingConfiguration>;
         /**
          * 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 {
         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;
         public _rootContainer = new Container("root");
         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 _layerToDispose: Layer;
+        public _layerToDispose: Nullable<Layer>;
         public _linkedControls = new Array<Control>();
         private _isFullscreen = false;
         private _fullscreenViewport = new Viewport(0, 0, 1, 1);
         private _idealWidth = 0;
         private _idealHeight = 0;
         private _renderAtIdealSize = false;
-        private _focusedControl: IFocusableControl;
+        private _focusedControl: Nullable<IFocusableControl>;
         private _blockNextFocusCheck = false;
 
         public get background(): string {
@@ -86,7 +86,7 @@ module BABYLON.GUI {
             this._onResize();
         }    
 
-        public get layer(): Layer {
+        public get layer(): Nullable<Layer> {
             return this._layerToDispose;
         }   
 
@@ -94,11 +94,11 @@ module BABYLON.GUI {
             return this._rootContainer;
         }
 
-        public get focusedControl(): IFocusableControl {
+        public get focusedControl(): Nullable<IFocusableControl> {
             return this._focusedControl;
         }
 
-        public set focusedControl(control: IFocusableControl) {
+        public set focusedControl(control: Nullable<IFocusableControl>) {
             if (this._focusedControl == control) {
                 return;
             }
@@ -114,11 +114,17 @@ module BABYLON.GUI {
             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);
 
-            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) {
                     return;
                 }
@@ -135,7 +141,7 @@ module BABYLON.GUI {
             this.hasAlpha = true;
 
             if (!width || !height) {
-                this._resizeObserver = this.getScene().getEngine().onResizeObservable.add(() => this._onResize());
+                this._resizeObserver = scene.getEngine().onResizeObservable.add(() => this._onResize());
                 this._onResize();
             }
 
@@ -171,23 +177,29 @@ module BABYLON.GUI {
             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) {
-                this.getScene().getEngine().onResizeObservable.remove(this._resizeObserver);
+                scene.getEngine().onResizeObservable.remove(this._resizeObserver);
             }
 
             if (this._pointerMoveObserver) {
-                this.getScene().onPrePointerObservable.remove(this._pointerMoveObserver);
+                scene.onPrePointerObservable.remove(this._pointerMoveObserver);
             }
 
             if (this._pointerObserver) {
-                this.getScene().onPointerObservable.remove(this._pointerObserver);
+                scene.onPointerObservable.remove(this._pointerObserver);
             }
 
             if (this._canvasPointerOutObserver) {
-                this.getScene().getEngine().onCanvasPointerOutObservable.remove(this._canvasPointerOutObserver);
+                scene.getEngine().onCanvasPointerOutObservable.remove(this._canvasPointerOutObserver);
             }
 
             if (this._layerToDispose) {
@@ -202,8 +214,14 @@ module BABYLON.GUI {
         }
 
         private _onResize(): void {
+            let scene = this.getScene();
+            
+            if (!scene) {
+                return;
+            }            
+
             // Check size
-            var engine = this.getScene().getEngine();
+            var engine = scene.getEngine();
             var textureSize = this.getSize();
             var renderWidth = engine.getRenderWidth();
             var renderHeight = engine.getRenderHeight();
@@ -243,6 +261,11 @@ module BABYLON.GUI {
 
             if (this._isFullscreen && this._linkedControls.length) {
                 var scene = this.getScene();
+
+                if (!scene) {
+                    return;
+                }
+
                 var globalViewport = this._getGlobalViewport(scene);
 
                 for (var control of this._linkedControls) {
@@ -260,7 +283,7 @@ module BABYLON.GUI {
                         continue;
                     }
                     
-                    var position = mesh.getBoundingInfo().boundingSphere.center;
+                    var position = (<BoundingInfo>mesh.getBoundingInfo()).boundingSphere.center;
                     var projectedPosition = Vector3.Project(position, mesh.getWorldMatrix(), scene.getTransformMatrix(), globalViewport);
 
                     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 {
             var scene = this.getScene();
+
+            if (!scene) {
+                return;
+            }
+
             var engine = scene.getEngine();
             var textureSize = this.getSize();
 
@@ -334,6 +362,10 @@ module BABYLON.GUI {
 
         public attach(): void {
             var scene = this.getScene();
+            if (!scene) {
+                return;
+            }
+
             this._pointerMoveObserver = scene.onPrePointerObservable.add((pi, state) => {
                 if (pi.type !== BABYLON.PointerEventTypes.POINTERMOVE 
                     && pi.type !== BABYLON.PointerEventTypes.POINTERUP
@@ -341,7 +373,15 @@ module BABYLON.GUI {
                     return;
                 }
 
+                if (!scene) {
+                    return;
+                }
+
                 let camera = scene.cameraToUseForPointers || scene.activeCamera;
+
+                if (!camera) {
+                    return;
+                }
                 let engine = scene.getEngine();
                 let viewport = camera.viewport;
                 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 {
             var scene = this.getScene();
+            if (!scene) {
+                return;
+            }            
             this._pointerObserver = scene.onPointerObservable.add((pi, state) => {
                 if (pi.type !== BABYLON.PointerEventTypes.POINTERMOVE 
                     && pi.type !== BABYLON.PointerEventTypes.POINTERUP
@@ -365,10 +408,13 @@ module BABYLON.GUI {
                     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 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) {
                     if (this._lastControlDown) {
                         this._lastControlDown.forcePointerUp();
@@ -445,7 +491,7 @@ module BABYLON.GUI {
             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);
 
             // Display

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

@@ -128,7 +128,7 @@ module BABYLON.GUI {
             var canvas = document.createElement("canvas");
             canvas.width = 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 data = image.data;
             

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

@@ -31,7 +31,7 @@ module BABYLON.GUI {
             return "Container";
         }           
 
-        public getChildByName(name: string): Control {
+        public getChildByName(name: string): Nullable<Control> {
             for (var child of this._children) {
                 if (child.name === name) {
                     return child;
@@ -41,7 +41,7 @@ module BABYLON.GUI {
             return null;
         }       
 
-        public getChildByType(name: string, type: string): Control {
+        public getChildByType(name: string, type: string): Nullable<Control> {
             for (var child of this._children) {
                 if (child.typeName === type) {
                     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);
 
             for (var child of this._children) {

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

@@ -5,9 +5,9 @@ module BABYLON.GUI {
         private _alpha = 1; 
         private _alphaSet = false; 
         private _zIndex = 0;
-        public _root: Container;
+        public _root: Nullable<Container>;
         public _host: AdvancedDynamicTexture;
-        public parent: Container;
+        public parent: Nullable<Container>;
         public _currentMeasure = Measure.Empty();
         private _fontFamily = "Arial";
         private _fontStyle = "";
@@ -39,7 +39,7 @@ module BABYLON.GUI {
         private _cachedOffsetX: number;
         private _cachedOffsetY: number;
         private _isVisible = true;
-        public _linkedMesh: AbstractMesh;
+        public _linkedMesh: Nullable<AbstractMesh>;
         private _fontSet = false;
         private _dummyVector2 = Vector2.Zero();
         private _downCount = 0;
@@ -522,7 +522,7 @@ module BABYLON.GUI {
             this.notRenderable = false;
         }
 
-        public linkWithMesh(mesh: AbstractMesh): void {
+        public linkWithMesh(mesh: Nullable<AbstractMesh>): void {
             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");
                 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._host = host;
         }

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

@@ -9,7 +9,7 @@ module BABYLON.GUI {
         private _imageHeight: number;
         private _loaded = false;
         private _stretch = Image.STRETCH_FILL;
-        private _source: string;
+        private _source: Nullable<string>;
         private _autoScale = false;
 
         private _sourceLeft = 0;
@@ -132,7 +132,7 @@ module BABYLON.GUI {
             this._markAsDirty();
         }
 
-        public set source(value: string) {
+        public set source(value: Nullable<string>) {
             if (this._source === value) {
                 return;
             }
@@ -145,11 +145,13 @@ module BABYLON.GUI {
             this._domImage.onload = () => {
                 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);
 
             this.source = url;
@@ -204,8 +206,10 @@ module BABYLON.GUI {
                             if (this._autoScale) {
                                 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;
                     }
                 }

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

@@ -15,9 +15,9 @@ module BABYLON.GUI {
         private _blinkTimeout: number;
         private _blinkIsEven = false;
         private _cursorOffset = 0;        
-        private _scrollLeft: number;
+        private _scrollLeft: Nullable<number>;
         private _textWidth: number;
-        private _clickedCoordinate: number;
+        private _clickedCoordinate: Nullable<number>;
         
         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 _dash = new Array<number>();
         private _connectedControl: Control;
-        private _connectedControlDirtyObserver: Observer<Control>;
+        private _connectedControlDirtyObserver: Nullable<Observer<Control>>;
 
         public get dash(): Array<number> {
             return this._dash;

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

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

+ 1 - 1
gui/src/math2D.ts

@@ -101,7 +101,7 @@ module BABYLON.GUI {
         private static _TempCompose1 = 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.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.
          */
-        public get imageProcessingConfiguration(): ImageProcessingConfiguration {
+        public get imageProcessingConfiguration(): Nullable<ImageProcessingConfiguration> {
             return this._imageProcessingConfiguration;
         }
 
@@ -286,26 +286,26 @@ namespace BABYLON {
          * Gets wether the color curves effect is enabled.
          */
         public get cameraColorCurvesEnabled(): boolean {
-            return this.imageProcessingConfiguration.colorCurvesEnabled;
+            return (<ImageProcessingConfiguration>this.imageProcessingConfiguration).colorCurvesEnabled;
         }
         /**
          * Sets wether the color curves effect is enabled.
          */
         public set cameraColorCurvesEnabled(value: boolean) {
-            this.imageProcessingConfiguration.colorCurvesEnabled = value;
+            (<ImageProcessingConfiguration>this.imageProcessingConfiguration).colorCurvesEnabled = value;
         }
 
         /**
          * Gets wether the color grading effect is enabled.
          */
         public get cameraColorGradingEnabled(): boolean {
-            return this.imageProcessingConfiguration.colorGradingEnabled;
+            return (<ImageProcessingConfiguration>this.imageProcessingConfiguration).colorGradingEnabled;
         }
         /**
          * Gets wether the color grading effect is enabled.
          */
         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.
          */
         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.
          */
         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). 
@@ -381,7 +381,7 @@ namespace BABYLON {
          * corresponding to low luminance, medium luminance, and high luminance areas respectively.
          */
         public set cameraColorCurves(value: Nullable<ColorCurves>) {
-            this._imageProcessingConfiguration.colorCurves = value;
+            (<ImageProcessingConfiguration>this.imageProcessingConfiguration).colorCurves = value;
         }
 
         /**
@@ -630,7 +630,7 @@ namespace BABYLON {
                 this.buildUniformLayout();
             }
 
-            if (!subMesh.effect.isReady()) {
+            if (!subMesh.effect || !subMesh.effect.isReady()) {
                 return false;
             }
 
@@ -695,6 +695,9 @@ namespace BABYLON {
             }
 
             var effect = subMesh.effect;
+            if (!effect) {
+                return;
+            }            
             this._activeEffect = effect;
 
             // Matrices
@@ -767,7 +770,7 @@ namespace BABYLON {
                 // Clip plane
                 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));
                 effect.setFloat3("vEyePosition",
                     eyePosition.x,
@@ -793,8 +796,6 @@ namespace BABYLON {
             this._uniformBuffer.update();
 
             this._afterBind(mesh);
-
-            scene = null;
         }
 
         /**

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

@@ -64,7 +64,7 @@ module BABYLON {
             return false;
         }
 
-        public getAlphaTestTexture(): BaseTexture {
+        public getAlphaTestTexture(): Nullable<BaseTexture> {
             return null;
         }
 
@@ -116,7 +116,7 @@ module BABYLON {
             defines._needNormals = MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights, this._disableLighting);
 
             // Values that need to be evaluated on every frame
-            MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances);
+            MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false);
             
             // Attribs
             MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true);
@@ -192,7 +192,7 @@ module BABYLON {
                     }, engine), defines);
 
             }
-            if (!subMesh.effect.isReady()) {
+            if (!subMesh.effect || !subMesh.effect.isReady()) {
                 return false;
             }
 
@@ -211,6 +211,9 @@ module BABYLON {
             }
 
             var effect = subMesh.effect;
+            if (!effect) {
+                return;
+            }
             this._activeEffect = effect;
 
             // Matrices        
@@ -237,7 +240,7 @@ module BABYLON {
                     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);

+ 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.
          */
-        private _imageProcessingObserver: Observer<ImageProcessingConfiguration>;
+        private _imageProcessingObserver: Nullable<Observer<ImageProcessingConfiguration>>;
 
         /**
          * Attaches a new image processing configuration to the Standard Material.
          * @param configuration 
          */
-        protected _attachImageProcessingConfiguration(configuration: ImageProcessingConfiguration): void {
+        protected _attachImageProcessingConfiguration(configuration: Nullable<ImageProcessingConfiguration>): void {
             if (configuration === this._imageProcessingConfiguration) {
                 return;
             }
@@ -413,13 +413,13 @@ module BABYLON {
         /**
          * Gets the Color Grading 2D Lookup Texture.
          */
-        public get cameraColorGradingTexture(): BaseTexture {
+        public get cameraColorGradingTexture(): Nullable<BaseTexture> {
             return this._imageProcessingConfiguration.colorGradingTexture;
         }
         /**
          * Sets the Color Grading 2D Lookup Texture.
          */
-        public set cameraColorGradingTexture(value: BaseTexture) {
+        public set cameraColorGradingTexture(value: Nullable<BaseTexture>) {
             this._imageProcessingConfiguration.colorGradingTexture = value;
         }
 
@@ -721,7 +721,7 @@ module BABYLON {
             MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true, true);
 
             // 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      
             if (defines.isDirty) {
@@ -861,7 +861,7 @@ module BABYLON {
                 this.buildUniformLayout();
             }
 
-            if (!subMesh.effect.isReady()) {
+            if (!subMesh.effect || !subMesh.effect.isReady()) {
                 return false;
             }
 
@@ -934,6 +934,9 @@ module BABYLON {
             }
 
             var effect = subMesh.effect;
+            if (!effect) {
+                return;
+            }
             this._activeEffect = effect;
 
             // Matrices        
@@ -1103,7 +1106,7 @@ module BABYLON {
                 // Colors
                 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);
             }
 
@@ -2033,7 +2036,7 @@ vColor=color;\n\
               this._isCreatedShader  = false;
             
             CustomMaterial.ShaderIndexer++;
-            var name: string = name + "custom_" + CustomMaterial.ShaderIndexer;
+            var name: string = "custom_" + CustomMaterial.ShaderIndexer;
 
             this.ReviewUniform("uniform",uniforms);
             this.ReviewUniform("sampler",samplers);
@@ -2041,7 +2044,10 @@ vColor=color;\n\
 
             var fn_afterBind = this._afterBind;
             this._afterBind = (m,e) => { 
-                this.AttachAfterBind(m,e);
+                if (!e) {
+                    return;
+                }
+                this.AttachAfterBind(m, 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 {
         @serializeAsTexture("diffuseTexture")
-        private _diffuseTexture: BaseTexture;
+        private _diffuseTexture: Nullable<BaseTexture>;
         @expandToProperty("_markAllSubMeshesAsTexturesDirty")
-        public diffuseTexture: BaseTexture;        
+        public diffuseTexture: Nullable<BaseTexture>;        
         
         @serializeAsTexture("distortionTexture")
-        private _distortionTexture: BaseTexture;
+        private _distortionTexture: Nullable<BaseTexture>;
         @expandToProperty("_markAllSubMeshesAsTexturesDirty")
-        public distortionTexture: BaseTexture;       
+        public distortionTexture: Nullable<BaseTexture>;       
         
         @serializeAsTexture("opacityTexture")
-        private _opacityTexture: BaseTexture;
+        private _opacityTexture: Nullable<BaseTexture>;
         @expandToProperty("_markAllSubMeshesAsTexturesDirty")
-        public opacityTexture: BaseTexture;
+        public opacityTexture: Nullable<BaseTexture>;
         
         @serialize("diffuseColor")
         public diffuseColor = new Color3(1, 1, 1);
@@ -60,7 +60,7 @@ module BABYLON {
             return true;
         }
 
-        public getAlphaTestTexture(): BaseTexture {
+        public getAlphaTestTexture(): Nullable<BaseTexture> {
             return null;
         }
 
@@ -107,7 +107,7 @@ module BABYLON {
             }
             
             // Values that need to be evaluated on every frame
-            MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances);
+            MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false);
             
             // Attribs
             MaterialHelper.PrepareDefinesForAttributes(mesh, defines, false, true);
@@ -147,7 +147,7 @@ module BABYLON {
                 
                 var join = defines.toString();
                 subMesh.setEffect(scene.getEngine().createEffect(shaderName,
-                    <EffectCreationOptions>{
+                    {
                         attributes: attribs,
                         uniformsNames: ["world", "view", "viewProjection", "vEyePosition",
                                 "vFogInfos", "vFogColor", "pointSize",
@@ -165,11 +165,13 @@ module BABYLON {
                         defines: join,
                         fallbacks: fallbacks,
                         onCompiled: this.onCompiled,
-                        onError: this.onError
+                        onError: this.onError,
+                        indexParameters: null,
+                        maxSimultaneousLights: 4
                     }, engine), defines);
             }
             
-            if (!subMesh.effect.isReady()) {
+            if (!subMesh.effect || !subMesh.effect.isReady()) {
                 return false;
             }
 
@@ -188,6 +190,9 @@ module BABYLON {
             }
 
             var effect = subMesh.effect;
+            if (!effect) {
+                return;
+            }
             this._activeEffect = effect;
 
             // Matrices
@@ -220,7 +225,7 @@ module BABYLON {
                     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);

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

@@ -107,7 +107,7 @@ module BABYLON {
             return false;
         }
 
-        public getAlphaTestTexture(): BaseTexture {
+        public getAlphaTestTexture(): Nullable<BaseTexture> {
             return null;
         }
         
@@ -187,7 +187,7 @@ module BABYLON {
             defines._needNormals = MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights, this._disableLighting);
 
             // Values that need to be evaluated on every frame
-            MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances);
+            MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false);
             
             // Attribs
             MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true);
@@ -269,7 +269,7 @@ module BABYLON {
                         indexParameters: { maxSimultaneousLights: this.maxSimultaneousLights }
                     }, engine), defines);
             }
-            if (!subMesh.effect.isReady()) {
+            if (!subMesh.effect || !subMesh.effect.isReady()) {
                 return false;
             }
 
@@ -288,6 +288,9 @@ module BABYLON {
             }
 
             var effect = subMesh.effect;
+            if (!effect) {
+                return;
+            }
             this._activeEffect = effect;
 
             // Matrices        
@@ -318,7 +321,7 @@ module BABYLON {
                     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);
@@ -405,7 +408,11 @@ module BABYLON {
             
             if (this._meshes) {
                 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();
                 }
             }

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

@@ -101,7 +101,7 @@ module BABYLON {
             return true;
         }
 
-        public getAlphaTestTexture(): BaseTexture {
+        public getAlphaTestTexture(): Nullable<BaseTexture> {
             return null;
         }
 
@@ -128,7 +128,7 @@ module BABYLON {
 
             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);
 
@@ -213,7 +213,7 @@ module BABYLON {
                         indexParameters: { maxSimultaneousLights: 4 }
                     }, engine), defines);
             }
-            if (!subMesh.effect.isReady()) {
+            if (!subMesh.effect || !subMesh.effect.isReady()) {
                 return false;
             }
 
@@ -232,6 +232,10 @@ module BABYLON {
             }
 
             var effect = subMesh.effect;
+            if (!effect) {
+                return;
+            }
+
             this._activeEffect = effect;
             
             // Matrices        
@@ -239,18 +243,18 @@ module BABYLON {
             this._activeEffect.setMatrix("viewProjection", scene.getTransformMatrix());
 
             // Bones
-            MaterialHelper.BindBonesParameters(mesh, this._effect);
+            MaterialHelper.BindBonesParameters(mesh, effect);
 
             if (this._mustRebind(scene, effect)) {
                 // Clip plane
-                MaterialHelper.BindClipPlane(this._effect, scene);
+                MaterialHelper.BindClipPlane(effect, scene);
 
                 // Point size
                 if (this.pointsCloud) {
                     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);

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

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

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

@@ -110,7 +110,7 @@ module BABYLON {
             return false;
         }
 
-        public getAlphaTestTexture(): BaseTexture {
+        public getAlphaTestTexture(): Nullable<BaseTexture> {
             return null;
         }
 
@@ -159,7 +159,7 @@ module BABYLON {
             defines._needNormals = MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights, this._disableLighting);
 
             // Values that need to be evaluated on every frame
-            MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances);
+            MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false);
             
             // Attribs
             MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true);
@@ -242,7 +242,7 @@ module BABYLON {
                         indexParameters: { maxSimultaneousLights: this.maxSimultaneousLights }
                     }, engine), defines);
             }
-            if (!subMesh.effect.isReady()) {
+            if (!subMesh.effect || !subMesh.effect.isReady()) {
                 return false;
             }
 
@@ -261,6 +261,10 @@ module BABYLON {
             }
 
             var effect = subMesh.effect;
+
+            if (!effect) {
+                return;
+            }
             this._activeEffect = effect;
 
             // Matrices        
@@ -291,7 +295,7 @@ module BABYLON {
                     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);

+ 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. 
          */
         @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). 
@@ -178,7 +178,7 @@ module BABYLON {
          * corresponding to low luminance, medium luminance, and high luminance areas respectively.
          */
         @serializeAsColorCurves()
-        public cameraColorCurves: ColorCurves = null;
+        public cameraColorCurves: Nullable<ColorCurves> = null;
          
         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._wasPreviouslyReady) {
                     return true;
@@ -679,11 +679,11 @@ module BABYLON {
 
             this._defines.reset();
 
-            if (scene.lightsEnabled && !this.disableLighting) {
+            if (scene.lightsEnabled && !this.disableLighting && mesh) {
                 MaterialHelper.PrepareDefinesForLights(scene, mesh, this._defines, true, this.maxSimultaneousLights);
             }
 
-            if (!this.checkReadyOnEveryCall) {
+            if (!this.checkReadyOnEveryCall && mesh) {
                 if (this._renderId === scene.getRenderId()) {
                     if (this._checkCache(scene, mesh, useInstances)) {
                         return true;
@@ -1009,7 +1009,7 @@ module BABYLON {
                 }
                 if (mesh.useBones && mesh.computeBonesUsingShaders) {
                     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
@@ -1017,8 +1017,8 @@ module BABYLON {
                     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_NORMAL = manager.supportsNormals && this._defines.NORMAL;
                     this._defines.MORPHTARGETS = (manager.numInfluencers > 0);
@@ -1093,7 +1093,7 @@ module BABYLON {
                 }
 
                 if (this._defines.NUM_BONE_INFLUENCERS > 0) {
-                    fallbacks.addCPUSkinningFallback(0, mesh);
+                    fallbacks.addCPUSkinningFallback(0, <Mesh>mesh);
                 }
 
                 //Attributes
@@ -1119,9 +1119,11 @@ module BABYLON {
                     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
                 var join = this._defines.toString();
@@ -1187,7 +1189,7 @@ module BABYLON {
                 
                 this.buildUniformLayout();
             }
-            if (!this._effect.isReady()) {
+            if (!this._effect || !this._effect.isReady()) {
                 return false;
             }
 
@@ -1259,19 +1261,26 @@ module BABYLON {
         }
 
         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 {
             this._myScene = this.getScene();
             var effect = this._effect;
+
+            if (!effect) {
+                return;
+            }
+
             // Matrices        
             this.bindOnlyWorldMatrix(world);
 
             // Bones
-            MaterialHelper.BindBonesParameters(mesh, this._effect);
+            MaterialHelper.BindBonesParameters(mesh, effect);
 
             if (this._myScene.getCachedMaterial() !== (<BABYLON.Material>this)) {
                 this._uniformBuffer.bindToEffect(effect, "Material");
@@ -1316,19 +1325,22 @@ module BABYLON {
 
                             if (this._defines.USESPHERICALFROMREFLECTIONMAP) {
                                 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.
                     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
@@ -1511,14 +1525,14 @@ module BABYLON {
                     }
 
                     if (this.cameraColorGradingTexture && StandardMaterial.ColorGradingTextureEnabled) {
-                        this._effect.setTexture("cameraColorGrading2DSampler", this.cameraColorGradingTexture);
+                        effect.setTexture("cameraColorGrading2DSampler", this.cameraColorGradingTexture);
 
                         let x = this.cameraColorGradingTexture.level;                 // Texture Level
                         let y = this.cameraColorGradingTexture.getSize().height;      // Texture Size example with 8
                         let z = y - 1.0;                    // SizeMinusOne 8 - 1
                         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 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 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
-                MaterialHelper.BindClipPlane(this._effect, this._myScene);
+                MaterialHelper.BindClipPlane(effect, this._myScene);
 
                 // Colors
                 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);
             }
 
-            if (this._myScene.getCachedMaterial() !== this || !this.isFrozen) {
+            if (mesh && (this._myScene.getCachedMaterial() !== this || !this.isFrozen)) {
 
                 // Lights
                 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
@@ -1555,11 +1569,11 @@ module BABYLON {
                 }
 
                 // Fog
-                MaterialHelper.BindFogParameters(this._myScene, mesh, this._effect);
+                MaterialHelper.BindFogParameters(this._myScene, mesh, effect);
 
                 // Morph targets
                 if (this._defines.NUM_MORPH_INFLUENCERS) {
-                    MaterialHelper.BindMorphTargetParameters(mesh, this._effect);                
+                    MaterialHelper.BindMorphTargetParameters(mesh, effect);                
                 }
 
                 this._cameraInfos.x = this.cameraExposure;
@@ -1567,11 +1581,11 @@ module BABYLON {
                 effect.setVector4("vCameraInfos", this._cameraInfos);
                 
                 if (this.cameraColorCurves) {
-                    ColorCurves.Bind(this.cameraColorCurves, this._effect);
+                    ColorCurves.Bind(this.cameraColorCurves, effect);
                 }
 
                 // Log. depth
-                MaterialHelper.BindLogDepth(this._defines, this._effect, this._myScene);
+                MaterialHelper.BindLogDepth(this._defines, effect, this._myScene);
             }
 
             this._uniformBuffer.update();

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

@@ -89,7 +89,7 @@ module BABYLON {
             return false;
         }
 
-        public getAlphaTestTexture(): BaseTexture {
+        public getAlphaTestTexture(): Nullable<BaseTexture> {
             return null;
         }
 
@@ -138,7 +138,7 @@ module BABYLON {
             defines._needNormals = MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights, this._disableLighting);
 
             // Values that need to be evaluated on every frame
-            MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances);
+            MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false);
             
             // Attribs
             MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true);
@@ -216,7 +216,7 @@ module BABYLON {
                         indexParameters: { maxSimultaneousLights: 4 }
                     }, engine), defines);
             }
-            if (!subMesh.effect.isReady()) {
+            if (!subMesh.effect || !subMesh.effect.isReady()) {
                 return false;
             }
 
@@ -235,6 +235,9 @@ module BABYLON {
             }
 
             var effect = subMesh.effect;
+            if (!effect) {
+                return;
+            }
             this._activeEffect = effect;
 
             // Matrices        
@@ -260,7 +263,7 @@ module BABYLON {
                     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);

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

@@ -32,7 +32,7 @@ module BABYLON {
             return false;
         }
 
-        public getAlphaTestTexture(): BaseTexture {
+        public getAlphaTestTexture(): Nullable<BaseTexture> {
             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);
 
@@ -155,7 +155,7 @@ module BABYLON {
                         indexParameters: { maxSimultaneousLights: 1 }
                     }, engine), defines);
             }
-            if (!subMesh.effect.isReady()) {
+            if (!subMesh.effect || !subMesh.effect.isReady()) {
                 return false;
             }
 
@@ -174,6 +174,9 @@ module BABYLON {
             }
 
             var effect = subMesh.effect;
+            if (!effect) {
+                return;
+            }
             this._activeEffect = effect;
 
             // Matrices        
@@ -194,7 +197,7 @@ module BABYLON {
 
                 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

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

@@ -56,7 +56,7 @@ module BABYLON {
             return false;
         }
 
-        public getAlphaTestTexture(): BaseTexture {
+        public getAlphaTestTexture(): Nullable<BaseTexture> {
             return null;
         }
 
@@ -105,7 +105,7 @@ module BABYLON {
             defines._needNormals = MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights, this._disableLighting);
 
             // Values that need to be evaluated on every frame
-            MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances);
+            MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false);
             
             // Attribs
             MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true);
@@ -181,7 +181,7 @@ module BABYLON {
                     }, engine), defines);
 
             }
-            if (!subMesh.effect.isReady()) {
+            if (!subMesh.effect || !subMesh.effect.isReady()) {
                 return false;
             }
 
@@ -200,6 +200,9 @@ module BABYLON {
             }
 
             var effect = subMesh.effect;
+            if (!effect) {
+                return;
+            }
             this._activeEffect = effect;
 
             // Matrices        
@@ -226,7 +229,7 @@ module BABYLON {
                     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);

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

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

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

@@ -95,7 +95,7 @@ module BABYLON {
             return false;
         }
 
-        public getAlphaTestTexture(): BaseTexture {
+        public getAlphaTestTexture(): Nullable<BaseTexture> {
             return null;
         }
 
@@ -146,7 +146,7 @@ module BABYLON {
             defines._needNormals = MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights, this._disableLighting);
 
             // Values that need to be evaluated on every frame
-            MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances);
+            MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false);
             
             // Attribs
             MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true);
@@ -227,7 +227,7 @@ module BABYLON {
                         indexParameters: { maxSimultaneousLights: this.maxSimultaneousLights }
                     }, engine), defines);
             }
-            if (!subMesh.effect.isReady()) {
+            if (!subMesh.effect || !subMesh.effect.isReady()) {
                 return false;
             }
 
@@ -246,6 +246,9 @@ module BABYLON {
             }
 
             var effect = subMesh.effect;
+            if (!effect) {
+                return;
+            }
             this._activeEffect = effect;
 
             // Matrices        
@@ -297,7 +300,7 @@ module BABYLON {
                     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);

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

@@ -99,7 +99,7 @@ module BABYLON {
             return false;
         }
 
-        public getAlphaTestTexture(): BaseTexture {
+        public getAlphaTestTexture(): Nullable<BaseTexture> {
             return null;
         }
 
@@ -167,7 +167,7 @@ module BABYLON {
             defines._needNormals = MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights, this._disableLighting);
 
             // Values that need to be evaluated on every frame
-            MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances);
+            MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false);
             
             // Attribs
             MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true);
@@ -239,7 +239,7 @@ module BABYLON {
                         indexParameters: { maxSimultaneousLights: this.maxSimultaneousLights }
                     }, engine), defines);
             }
-            if (!subMesh.effect.isReady()) {
+            if (!subMesh.effect || !subMesh.effect.isReady()) {
                 return false;
             }
 
@@ -258,6 +258,9 @@ module BABYLON {
             }
 
             var effect = subMesh.effect;
+            if (!effect) {
+                return;
+            }
             this._activeEffect = effect;
 
             // Matrices        
@@ -297,7 +300,7 @@ module BABYLON {
                     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);

+ 2 - 1
materialsLibrary/src/tsconfig.json

@@ -6,6 +6,7 @@
     "noImplicitAny": true,
     "noImplicitReturns": 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 _mesh: AbstractMesh = null;
+        private _mesh: Nullable<AbstractMesh> = null;
 
         private _refractionRTT: RenderTargetTexture;
         private _reflectionRTT: RenderTargetTexture;
@@ -191,8 +191,13 @@ module BABYLON {
 
         // Methods
         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 {
@@ -202,7 +207,7 @@ module BABYLON {
             this._reflectionRTT.refreshRate = refreshRate;
         }
 
-        public getRenderList(): AbstractMesh[] {
+        public getRenderList(): Nullable<AbstractMesh[]> {
             return this._refractionRTT.renderList;
         }
 
@@ -218,7 +223,7 @@ module BABYLON {
             return false;
         }
 
-        public getAlphaTestTexture(): BaseTexture {
+        public getAlphaTestTexture(): Nullable<BaseTexture> {
             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);
 
@@ -373,7 +378,7 @@ module BABYLON {
                     }, engine), defines);
 
             }
-            if (!subMesh.effect.isReady()) {
+            if (!subMesh.effect || !subMesh.effect.isReady()) {
                 return false;
             }
 
@@ -392,6 +397,9 @@ module BABYLON {
             }
 
             var effect = subMesh.effect;
+            if (!effect || !this._mesh) {
+                return;
+            }
             this._activeEffect = effect;
 
             // Matrices        
@@ -417,7 +425,7 @@ module BABYLON {
                     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);
@@ -485,7 +493,7 @@ module BABYLON {
             this._reflectionRTT.ignoreCameraViewport = true;
 
             var isVisible: boolean;
-            var clipPlane: Plane = null;
+            var clipPlane: Nullable<Plane> = null;
             var savedViewMatrix: Matrix;
             var mirrorMatrix = Matrix.Zero();
 

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

@@ -1086,12 +1086,8 @@
 
             // Constants
             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;
 
             // Extensions
@@ -1316,7 +1312,7 @@
             return this._drawCalls;
         }
 
-        public getDepthFunction(): number {
+        public getDepthFunction(): Nullable<number> {
             return this._depthCullingState.depthFunc;
         }
 

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

@@ -60,12 +60,12 @@
             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.isBackground = isBackground === undefined ? true : isBackground;
             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);
 
             var engine = this._scene.getEngine();

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

@@ -496,13 +496,13 @@
         /**
          * Gets the Color Grading 2D Lookup Texture.
          */
-        public get cameraColorGradingTexture(): BaseTexture {
+        public get cameraColorGradingTexture(): Nullable<BaseTexture> {
             return this._imageProcessingConfiguration.colorGradingTexture;
         }
         /**
          * Sets the Color Grading 2D Lookup Texture.
          */
-        public set cameraColorGradingTexture(value: BaseTexture) {
+        public set cameraColorGradingTexture(value: Nullable<BaseTexture>) {
             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; 
          * corresponding to low luminance, medium luminance, and high luminance areas respectively.
          */
-        public get cameraColorCurves(): ColorCurves {
+        public get cameraColorCurves(): Nullable<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; 
          * 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;
         }
 

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

@@ -7,7 +7,7 @@ module BABYLON {
         private _context: CanvasRenderingContext2D;
         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);
 
             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 
          */
         @serializeAsColorCurves()
-        public colorCurves = new ColorCurves();
+        public colorCurves: Nullable<ColorCurves> = new ColorCurves();
 
         @serialize()
         private _colorCurvesEnabled = false;
@@ -56,7 +56,7 @@ module BABYLON {
          * Color grading LUT texture used in the effect if colorGradingEnabled is set to true 
          */
         @serializeAsTexture()
-        public colorGradingTexture: BaseTexture;
+        public colorGradingTexture: Nullable<BaseTexture>;
 
         @serialize()
         private _colorGradingEnabled = false;
@@ -354,7 +354,12 @@ module BABYLON {
             defines.EXPOSURE = (this.exposure !== 1.0);
             defines.COLORCURVES = (this.colorCurvesEnabled && !!this.colorCurves);
             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.SAMPLER3DBGRMAP = this.colorGradingBGR;
             defines.IMAGEPROCESSINGPOSTPROCESS = this.applyByPostProcess;
@@ -375,7 +380,7 @@ module BABYLON {
          */
         public bind(effect: Effect, aspectRatio = 1) : void {
             // Color Curves
-            if (this._colorCurvesEnabled) {
+            if (this._colorCurvesEnabled && this.colorCurves) {
                 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.
          */
-        public get cameraColorGradingTexture(): BaseTexture {
+        public get cameraColorGradingTexture(): Nullable<BaseTexture> {
             return this._imageProcessingConfiguration.colorGradingTexture;
         }
         /**
          * Sets the Color Grading 2D Lookup Texture.
          */
-        public set cameraColorGradingTexture(value: BaseTexture) {
+        public set cameraColorGradingTexture(value: Nullable<BaseTexture> ) {
             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; 
          * corresponding to low luminance, medium luminance, and high luminance areas respectively.
          */
-        public get cameraColorCurves(): ColorCurves {
+        public get cameraColorCurves(): Nullable<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; 
          * 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;
         }        
 

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

@@ -45,7 +45,7 @@ module BABYLON {
         private _deltaRotationConjugated: Quaternion;
 
         //If set, this is this impostor's parent
-        private _parent: PhysicsImpostor;
+        private _parent: Nullable<PhysicsImpostor>;
 
         private _isDisposed = false;
 
@@ -199,11 +199,11 @@ module BABYLON {
             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;
         }
 

+ 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 .
          */
-        public get colorCurves(): ColorCurves {
+        public get colorCurves(): Nullable<ColorCurves> {
             return this.imageProcessingConfiguration.colorCurves;
         }
         /**
          * 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;
         }
 
@@ -104,13 +104,13 @@
         /**
          * 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;
         }
         /**
          * 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;
         }
 

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

@@ -14,7 +14,7 @@
         */
         public onDisposeObservable = new Observable<SpriteManager>();
 
-        private _onDisposeObserver: Observer<SpriteManager>;
+        private _onDisposeObserver: Nullable<Observer<SpriteManager>>;
         public set onDispose(callback: () => void) {
             if (this._onDisposeObserver) {
                 this.onDisposeObservable.remove(this._onDisposeObserver);
@@ -137,12 +137,12 @@
             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 min = Vector3.Zero();
             var max = Vector3.Zero();
             var distance = Number.MAX_VALUE;
-            var currentSprite: Sprite;
+            var currentSprite: Nullable<Sprite> = null;
             var cameraSpacePosition = Vector3.Zero();
             var cameraView = camera.getViewMatrix();
 
@@ -262,17 +262,17 @@
         public dispose(): void {
             if (this._buffer) {
                 this._buffer.dispose();
-                this._buffer = null;
+                (<any>this._buffer) = null;
             }
 
             if (this._indexBuffer) {
                 this._scene.getEngine()._releaseBuffer(this._indexBuffer);
-                this._indexBuffer = null;
+                (<any>this._indexBuffer) = null;
             }
 
             if (this._spriteTexture) {
                 this._spriteTexture.dispose();
-                this._spriteTexture = null;
+                (<any>this._spriteTexture) = null;
             }
 
             // Remove from scene

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

@@ -5,9 +5,9 @@
         private _isBlendEquationParametersDirty = false;
         private _isBlendConstantsDirty = 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.
@@ -123,7 +123,7 @@
 
             // Alpha function
             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;
             }
 
@@ -135,7 +135,7 @@
 
             // Constants
             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;
             }                    
         }

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


Algúns arquivos non se mostraron porque demasiados arquivos cambiaron neste cambio