Browse Source

Merge pull request #2584 from bghgary/misc-fixes

Fix BaseTexture.WhenAllReady with empty textures argument and typo
sebavan 8 years ago
parent
commit
515b5a08e8
1 changed files with 14 additions and 10 deletions
  1. 14 10
      src/Materials/Textures/babylon.baseTexture.ts

+ 14 - 10
src/Materials/Textures/babylon.baseTexture.ts

@@ -332,28 +332,32 @@
             return serializationObject;
         }
 
-        public static WhenAllReady(textures: BaseTexture[], onLoad: () => void): void {
-            var numReady = 0;
+        public static WhenAllReady(textures: BaseTexture[], callback: () => void): void {
+            let numRemaining = textures.length;
+            if (numRemaining === 0) {
+                callback();
+                return;
+            }
 
             for (var i = 0; i < textures.length; i++) {
                 var texture = textures[i];
 
                 if (texture.isReady()) {
-                    if (++numReady === textures.length) {
-                        onLoad();
+                    if (--numRemaining === 0) {
+                        callback();
                     }
                 }
                 else {
-                    var observable = (texture as any).onLoadObservable as Observable<Texture>;
+                    var onLoadObservable = (texture as any).onLoadObservable as Observable<Texture>;
 
-                    let callback = () => {
-                        observable.removeCallback(callback);
-                        if (++numReady === textures.length) {
-                            onLoad();
+                    let onLoadCallback = () => {
+                        onLoadObservable.removeCallback(onLoadCallback);
+                        if (--numRemaining === 0) {
+                            callback();
                         }
                     };
 
-                    observable.add(callback);
+                    onLoadObservable.add(onLoadCallback);
                 }
             }
         }