Skip to content

Commit

Permalink
Audio: Prevent null source error in Audio.disconnect() (#26597)
Browse files Browse the repository at this point in the history
**Problem**

Audio.disconnect() expects Audio.source is non-null and
calls Audio.source.disconnect(). But Audio.source is
initialized as null in the constructor and later it is
set in .play() or set*() methods.

So if Audio.disconnect() is called before starting to
play or setting source, it can cause an error when
attemping to call Audio.source.disconnect()

**Solution**

Add a guard in Audio.disconnect()
  • Loading branch information
takahirox committed Aug 21, 2023
1 parent f53bb7d commit 6ce2492
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/audio/Audio.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,12 @@ class Audio extends Object3D {

disconnect() {

if ( this._connected === false ) {

return;

}

if ( this.filters.length > 0 ) {

this.source.disconnect( this.filters[ 0 ] );
Expand Down

0 comments on commit 6ce2492

Please sign in to comment.