Skip to content

Commit

Permalink
Merge pull request #6217 from mozilla/AudioDisconnectGuard
Browse files Browse the repository at this point in the history
bitECS: Prevent Three.js Audio.disconnect error
  • Loading branch information
takahirox authored Aug 16, 2023
2 parents 7946c36 + e9c5702 commit 0a89bdd
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/bit-systems/audio-emitter-system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ export function isPositionalAudio(node: AudioObject3D): node is PositionalAudio

export function cleanupAudio(audio: AudioObject3D) {
const eid = audio.eid!;
audio.disconnect();
if (audio.source !== null) {
audio.disconnect();
}
const audioSystem = APP.scene?.systems["hubs-systems"].audioSystem;
APP.audios.delete(eid);
APP.supplementaryAttenuation.delete(eid);
Expand All @@ -34,7 +36,9 @@ function swapAudioType<T extends AudioObject3D>(
NewType: AudioConstructor<T>
) {
const audio = world.eid2obj.get(eid)! as AudioObject3D;
audio.disconnect();
if (audio.source !== null) {
audio.disconnect();
}
APP.sourceType.set(eid, SourceType.MEDIA_VIDEO);
APP.supplementaryAttenuation.delete(eid);
APP.audios.delete(eid);
Expand Down

0 comments on commit 0a89bdd

Please sign in to comment.