NiklasEi/bevy_kira_audio

SoundLimitReached causes Panic

Elogain opened this issue · 6 comments

Hello again! Upgraded to latest version. Ended up being in a scenario where the amount of sounds played (not super-crazy) caused a panic here: https://github.com/NiklasEi/bevy_kira_audio/blob/main/src/audio_output.rs#L167

This is the full error message: thread 'main' panicked at 'Failed to play sound: SoundLimitReached'

I'm wondering if there is a way to get the limit by code? If so I guess I can implement a rate-limiter on sounds on my side. However I think it would be nice to propagate this error up to the user of bevy_kira_audio :)

The Kira settings for sound and command limits are exposed now. See the stress-test example: https://github.com/NiklasEi/bevy_kira_audio/blob/main/examples/stress_test.rs#L16-L19

The Kira settings for sound and command limits are exposed now. See the stress-test example: https://github.com/NiklasEi/bevy_kira_audio/blob/main/examples/stress_test.rs#L16-L19

Does this resolve the issue for you?

Yeah, I've increased it a lot and also limiting the amount of sounds I add! Thanks!

Is it not a better idea to make this fallible? I would much rather it returned an error and control what I do when it fails (likely ignore it) than have it panic on my behalf.

We cannot return an error, because the sound playing is deferred and done in a separate system (comparable to Bevy's commands). The panic was removed in #51. Instead, we now log a warning and the play command is dropped.
If you have a very important sound where you want to track if it started playing, you can do so by checking the playback state with the instance handle.

Ah gotcha, thank you for the insight, and for the great library! :)