Browse Source

Merge pull request #6026 from BabylonJS/dispose-fix

Associated with #6019
David Catuhe 6 years ago
parent
commit
e934ac13a8
1 changed files with 27 additions and 3 deletions
  1. 27 3
      src/assetContainer.ts

+ 27 - 3
src/assetContainer.ts

@@ -132,7 +132,7 @@ export class AssetContainer extends AbstractScene {
             this.scene.removeReflectionProbe(o);
         });
 
-        if (this.environmentTexture == this.scene.environmentTexture) {
+        if (this.environmentTexture === this.scene.environmentTexture) {
             this.scene.environmentTexture = null;
         }
 
@@ -148,42 +148,66 @@ export class AssetContainer extends AbstractScene {
         this.cameras.forEach((o) => {
             o.dispose();
         });
+        this.cameras = [];
+
         this.lights.forEach((o) => {
             o.dispose();
         });
+        this.lights = [];
+
         this.meshes.forEach((o) => {
             o.dispose();
         });
+        this.meshes = [];
+
         this.skeletons.forEach((o) => {
             o.dispose();
         });
+        this.skeletons = [];
+
         this.animationGroups.forEach((o) => {
             o.dispose();
         });
+        this.animationGroups = [];
+
         this.multiMaterials.forEach((o) => {
             o.dispose();
         });
+        this.multiMaterials = [];
+
         this.materials.forEach((o) => {
             o.dispose();
         });
+        this.materials = [];
+
         this.geometries.forEach((o) => {
             o.dispose();
         });
+        this.geometries = [];
+        
         this.transformNodes.forEach((o) => {
             o.dispose();
         });
+        this.transformNodes = [];
+
         this.actionManagers.forEach((o) => {
             o.dispose();
         });
+        this.actionManagers = [];
+
         this.textures.forEach((o) => {
             o.dispose();
         });
+        this.textures = [];
+
         this.reflectionProbes.forEach((o) => {
             o.dispose();
         });
+        this.reflectionProbes = [];
 
-        if (this.scene.environmentTexture) {
-            this.scene.environmentTexture.dispose();
+        if (this.environmentTexture) {
+            this.environmentTexture.dispose();
+            this.environmentTexture = null;
         }
 
         for (let component of this.scene._serializableComponents) {