Skip to content

Commit

Permalink
fix: fix critical position audio play memory leak
Browse files Browse the repository at this point in the history
  • Loading branch information
zardoy committed Apr 16, 2024
1 parent 53a6d78 commit 19a5d03
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions prismarine-viewer/viewer/lib/viewer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,12 @@ export class Viewer {
this.scene.add(sound)
// set sound position
sound.position.set(position.x, position.y, position.z)
sound.play()
sound.onEnded = () => {
this.scene.remove(sound)
sound.disconnect()
audioLoader.manager.itemEnd(path)
}
sound.play()
})
}

Expand Down Expand Up @@ -176,18 +177,18 @@ export class Viewer {
emitter.on('time', (timeOfDay) => {
let skyLight = 15
if (timeOfDay < 0 || timeOfDay > 24000) {
throw new Error("Invalid time of day. It should be between 0 and 24000.");
throw new Error("Invalid time of day. It should be between 0 and 24000.")
} else if (timeOfDay <= 6000 || timeOfDay >= 18000) {
skyLight = 15;
skyLight = 15
} else if (timeOfDay > 6000 && timeOfDay < 12000) {
skyLight = 15 - ((timeOfDay - 6000) / 6000) * 15;
skyLight = 15 - ((timeOfDay - 6000) / 6000) * 15
} else if (timeOfDay >= 12000 && timeOfDay < 18000) {
skyLight = ((timeOfDay - 12000) / 6000) * 15;
skyLight = ((timeOfDay - 12000) / 6000) * 15
}

if (this.world.skyLight === skyLight) return
this.world.skyLight = skyLight
;(this.world as WorldRendererThree).rerenderAllChunks?.()
; (this.world as WorldRendererThree).rerenderAllChunks?.()
})

emitter.emit('listening')
Expand Down

0 comments on commit 19a5d03

Please sign in to comment.