Browse Source

Merge pull request #7046 from kirbysayshi/patch-1

Prevent an infinite loop during engine dispose in a scene with multiple soundtracks
David Catuhe 5 years ago
parent
commit
5e024ebf31

+ 1 - 0
dist/preview release/what's new.md

@@ -204,6 +204,7 @@
 - Fixed bug where vignette aspect ratio would be wrong when rendering direct to canvas
 - Fixed bug where vignette aspect ratio would be wrong when rendering direct to canvas
 - Fixed Path2 length computation ([Poolminer](https://github.com/Poolminer/))
 - Fixed Path2 length computation ([Poolminer](https://github.com/Poolminer/))
 - Cloning of `ShaderMaterial` also clone `shaderPath` and `options` properties ([Popov72](https://github.com/Popov72))
 - Cloning of `ShaderMaterial` also clone `shaderPath` and `options` properties ([Popov72](https://github.com/Popov72))
+- Prevent an infinite loop when calling `engine.dispose()` in a scene with multiple `SoundTracks` defined ([kirbysayshi](https://github.com/kirbysayshi))
 
 
 ## Breaking changes
 ## Breaking changes
 
 

+ 1 - 3
src/Audio/soundTrack.ts

@@ -35,7 +35,6 @@ export class SoundTrack {
 
 
     private _outputAudioNode: Nullable<GainNode>;
     private _outputAudioNode: Nullable<GainNode>;
     private _scene: Scene;
     private _scene: Scene;
-    private _isMainTrack: boolean = false;
     private _connectedAnalyser: Analyser;
     private _connectedAnalyser: Analyser;
     private _options: ISoundTrackOptions;
     private _options: ISoundTrackOptions;
     private _isInitialized = false;
     private _isInitialized = false;
@@ -51,7 +50,7 @@ export class SoundTrack {
         this.soundCollection = new Array();
         this.soundCollection = new Array();
         this._options = options;
         this._options = options;
 
 
-        if (!this._isMainTrack && this._scene.soundTracks) {
+        if (!this._options.mainTrack && this._scene.soundTracks) {
             this._scene.soundTracks.push(this);
             this._scene.soundTracks.push(this);
             this.id = this._scene.soundTracks.length - 1;
             this.id = this._scene.soundTracks.length - 1;
         }
         }
@@ -64,7 +63,6 @@ export class SoundTrack {
 
 
             if (this._options) {
             if (this._options) {
                 if (this._options.volume) { this._outputAudioNode.gain.value = this._options.volume; }
                 if (this._options.volume) { this._outputAudioNode.gain.value = this._options.volume; }
-                if (this._options.mainTrack) { this._isMainTrack = this._options.mainTrack; }
             }
             }
 
 
             this._isInitialized = true;
             this._isInitialized = true;

+ 3 - 3
tests/unit/babylon/src/Loading/babylon.sceneLoader.tests.ts

@@ -517,9 +517,9 @@ describe('Babylon Scene Loader', function() {
                 expect(result.meshes.length, "meshes.length").to.equal(scene.meshes.length);
                 expect(result.meshes.length, "meshes.length").to.equal(scene.meshes.length);
                 expect(result.particleSystems.length, "particleSystems.length").to.equal(0);
                 expect(result.particleSystems.length, "particleSystems.length").to.equal(0);
                 expect(result.animationGroups.length, "animationGroups.length").to.equal(3);
                 expect(result.animationGroups.length, "animationGroups.length").to.equal(3);
-                expect(scene.soundTracks.length, "scene.soundTracks.length").to.equal(1);
-                expect(scene.soundTracks[0].soundCollection.length, "scene.soundTracks[0].soundCollection.length").to.equal(3);
-                expect(scene.soundTracks[0].soundCollection[0].onEndedObservable.hasObservers(), "scene.soundTracks[0].soundCollection[0].onEndedObservable.hasObservers()").to.be.true;
+                expect(scene.soundTracks.length, "scene.soundTracks.length").to.equal(0);
+                expect(scene.mainSoundTrack.soundCollection.length, "scene.mainSoundTrack.soundCollection.length").to.equal(3);
+                expect(scene.mainSoundTrack.soundCollection[0].onEndedObservable.hasObservers(), "scene.mainSoundTrack.soundCollection[0].onEndedObservable.hasObservers()").to.be.true;
             });
             });
         });
         });