瀏覽代碼

only dispose assetContainer objects when its disposed

Trevor Baron 6 年之前
父節點
當前提交
2abdab7462

+ 5 - 1
src/Audio/audioSceneComponent.ts

@@ -275,8 +275,9 @@ export class AudioSceneComponent implements ISceneSerializableComponent {
     /**
      * Removes all the elements in the container from the scene
      * @param container contains the elements to remove
+     * @param dispose if the removed element should be disposed (default: false)
      */
-    public removeFromContainer(container: AbstractScene): void {
+    public removeFromContainer(container: AbstractScene, dispose = false): void {
         if (!container.sounds) {
             return;
         }
@@ -284,6 +285,9 @@ export class AudioSceneComponent implements ISceneSerializableComponent {
             sound.stop();
             sound.autoplay = false;
             this.scene.mainSoundTrack.RemoveSound(sound);
+            if(dispose){
+                sound.dispose();
+            }
         });
     }
 

+ 5 - 1
src/Layers/effectLayerSceneComponent.ts

@@ -149,13 +149,17 @@ export class EffectLayerSceneComponent implements ISceneSerializableComponent {
     /**
      * Removes all the elements in the container from the scene
      * @param container contains the elements to remove
+     * @param dispose if the removed element should be disposed (default: false)
      */
-    public removeFromContainer(container: AbstractScene): void {
+    public removeFromContainer(container: AbstractScene, dispose?: boolean): void {
         if (!container.effectLayers) {
             return;
         }
         container.effectLayers.forEach((o) => {
             this.scene.removeEffectLayer(o);
+            if(dispose){
+                o.dispose();
+            }
         });
     }
 

+ 5 - 1
src/LensFlares/lensFlareSystemSceneComponent.ts

@@ -149,13 +149,17 @@ export class LensFlareSystemSceneComponent implements ISceneSerializableComponen
     /**
      * Removes all the elements in the container from the scene
      * @param container contains the elements to remove
+     * @param dispose if the removed element should be disposed (default: false)
      */
-    public removeFromContainer(container: AbstractScene): void {
+    public removeFromContainer(container: AbstractScene, dispose?: boolean): void {
         if (!container.lensFlareSystems) {
             return;
         }
         container.lensFlareSystems.forEach((o) => {
             this.scene.removeLensFlareSystem(o);
+            if(dispose){
+                o.dispose();
+            }
         });
     }
 

+ 2 - 1
src/Lights/Shadows/shadowGeneratorSceneComponent.ts

@@ -83,8 +83,9 @@ export class ShadowGeneratorSceneComponent implements ISceneSerializableComponen
     /**
      * Removes all the elements in the container from the scene
      * @param container contains the elements to remove
+     * @param dispose if the removed element should be disposed (default: false)
      */
-    public removeFromContainer(container: AbstractScene): void {
+    public removeFromContainer(container: AbstractScene, dispose?: boolean): void {
         // Nothing To Do Here. (directly attached to a light)
     }
 

+ 1 - 1
src/assetContainer.ts

@@ -177,7 +177,7 @@ export class AssetContainer extends AbstractScene {
         });
 
         for (let component of this.scene._serializableComponents) {
-            component.dispose();
+            component.removeFromContainer(this, true);
         }
     }
 

+ 2 - 1
src/sceneComponent.ts

@@ -129,8 +129,9 @@ export interface ISceneSerializableComponent extends ISceneComponent {
     /**
      * Removes all the elements in the container from the scene
      * @param container contains the elements to remove
+     * @param dispose if the removed element should be disposed (default: false)
      */
-    removeFromContainer(container: AbstractScene): void;
+    removeFromContainer(container: AbstractScene, dispose?: boolean): void;
 
     /**
      * Serializes the component data to the specified json object