Combination using scene.dispose() and WebAudio in BABYLON

Hello again for a different post. In my playground example, in version 4.2 and the newest alpha,

Playground Example

I noticed that when I used first WebAudio in Babylon.js, then dispose the scene to create a new scene, it would practically hang forever.

   //soundTrack.ts
   public dispose(): void {
        if (Engine.audioEngine && Engine.audioEngine.canUseWebAudio) {
            if (this._connectedAnalyser) {
                this._connectedAnalyser.stopDebugCanvas();
            }
            while (this.soundCollection.length) {
                this.soundCollection[0].dispose(); //line that is hanging.
            }
            if (this._outputAudioNode) {
                this._outputAudioNode.disconnect();
            }
            this._outputAudioNode = null;
        }
    }

I tried a source trace and seemed to be in an endless loop on soundTrack.ts around lines 81 (version 4.2) where by only one existing item in the collection would not break out of the loop.

Am I doing something wrong or is this a forbidden method in Babylon.js?

Looks like a bug to me, unless a sound collection removes it self from scene. Soundcollection. It probably is supposed to.

How I iterate through things like this is:

For(let i = this.soundCollection.length - 1; i >= 0; i–){… }

Yup sounds definitely like a bug, I ll fix it for the next nightly.

1 Like

I am actually not reproducing an infinite loop with your playground ???

Only the loading screen is staying cause you disposed the scene whilst loading.

Are you able to create the infinite loop in this PG ???

https://playground.babylonjs.com/#TIHQQ1#1 In this exmple, the scene.dispose() is removed and the scene including the box is displayed although small.

I realized it was a loop by using DevTools by the browser and it just stays in the while loop where the comment is in the soundTrack.ts topic post example.

Thanks.

This does not repro for me :frowning:

Maybe @RaananW could repro ???

The Sound class removes itself from soundtrack if it has a soundtrack id.

If the repsoruction is running this scene and running it again - i am sorry, i can’t reproduce it.
Are there any other steps i need to take to get that to fail?