Browse Source

add disposeTexture to particleSystem.dispose()

David Catuhe 7 years ago
parent
commit
01d4016e76

+ 2 - 1
src/Particles/babylon.IParticleSystem.ts

@@ -131,8 +131,9 @@ module BABYLON {
         render(): number;
         /**
          * Dispose the particle system and frees its associated resources.
+         * @param disposeTexture defines if the particule texture must be disposed as well (true by default)
          */
-        dispose(): void;
+        dispose(disposeTexture: boolean): void;
         /**
          * Clones the particle system.
          * @param name The name of the cloned object

+ 8 - 2
src/Particles/babylon.gpuParticleSystem.ts

@@ -638,9 +638,10 @@
         }
 
         /**
-         * Disposes the particle system and free the associated resources.
+         * Disposes the particle system and free the associated resources
+         * @param disposeTexture defines if the particule texture must be disposed as well (true by default)
          */
-        public dispose(): void {
+        public dispose(disposeTexture = true): void {
             var index = this._scene.particleSystems.indexOf(this);
             if (index > -1) {
                 this._scene.particleSystems.splice(index, 1);
@@ -655,6 +656,11 @@
                 (<any>this._randomTexture) = null;
             }
 
+            if (disposeTexture && this.particleTexture) {
+                this.particleTexture.dispose();
+                this.particleTexture = null;
+            }            
+
             // Callback
             this.onDisposeObservable.notifyObservers(this);
             this.onDisposeObservable.clear();

+ 4 - 3
src/Particles/babylon.particleSystem.ts

@@ -831,9 +831,10 @@
         }
 
         /**
-         * Disposes the particle system and free the associated resources.
+         * Disposes the particle system and free the associated resources
+         * @param disposeTexture defines if the particule texture must be disposed as well (true by default)
          */
-        public dispose(): void {
+        public dispose(disposeTexture = true): void {
             if (this._vertexBuffer) {
                 this._vertexBuffer.dispose();
                 this._vertexBuffer = null;
@@ -844,7 +845,7 @@
                 this._indexBuffer = null;
             }
 
-            if (this.particleTexture) {
+            if (disposeTexture && this.particleTexture) {
                 this.particleTexture.dispose();
                 this.particleTexture = null;
             }