Spamming playAudio allows playing multiple tunes at once
SquidDev opened this issue ยท 1 comments
This was initially discovered testing #451, but I'm able to reproduce without it. It's strictly speaking a bug in Minecraft's sounds system, but we should probably find a way around it.
Steps to reproduce
-
Run the following code on a computer with a disk drive and record inside:
local p = peripheral.find("drive") while true do p.playAudio() sleep(0.05) end
-
Wait for some time (anywhere from a couple of seconds to several minutes). Doing other things (like placing blocks) may help, or it just may help pass the time.
-
The song will continually be restarted, but eventually you'll have one tune continue playing.
-
Observe this in your logs:
[12:47:40] [Thread-3/ERROR]: Error in class 'SourceLWJGL OpenAL' [12:47:40] [Thread-3/ERROR]: Channel null in method 'stop'
Diagnosis
From what I can tell, Minecraft's sound system will process stopping sounds before playing new ones. This means it's possible to stop a sound which has not yet been played, meaning the "play" event is then never stopped.
Solutions
I've tried a couple of client-side solutions, such as using ITickableSound.isDonePlaying
to delay stopping the sound by a couple of ticks, but the problem still seems to resurface. I'd really like other people to experiment too, to see if they can a) reproduce the problem and b) fix it.
I've thought about some server-side solutions, like rate limiting playAudio
/stopAudio
, but I suspect it'd still be possible to cause this though other means, such as carefully timing a playAudio
call, then breaking the drive.