Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unwrap panic in audio_playback_device_spec #1357

Open
fschulze opened this issue Dec 27, 2023 · 2 comments
Open

unwrap panic in audio_playback_device_spec #1357

fschulze opened this issue Dec 27, 2023 · 2 comments

Comments

@fschulze
Copy link

Great wrapper!

I get a panic due to a failing unwrap in audio_playback_device_spec on macOS when trying to get the spec of the first device which is an external HDMI display (I hope the backtrace is useful, as it isn't a native one):

Backtrace (most recent call last):
  File "~/.cargo/registry/src/index.crates.io-6f17d22bba15001f/sdl2-0.36.0/src/sdl2/audio.rs:202", in sdl2::audio::<impl sdl2::sdl::AudioSubsystem>::audio_playback_device_spec
    Ok(AudioSpec::convert_from_ll(spec))
  File "~/.cargo/registry/src/index.crates.io-6f17d22bba15001f/sdl2-0.36.0/src/sdl2/audio.rs:721", in sdl2::audio::AudioSpec::convert_from_ll
    format: AudioFormat::from_ll(spec.format).unwrap(),
  File "rust:library/core/src/option.rs:935", in core::option::Option<T>::unwrap
  File "rust:library/core/src/panicking.rs:127", in core::panicking::panic

I would expect audio_playback_device_spec to return an error instead.

It looks like audio_playback_device_spec is new in 0.36, which isn't mentioned in the changelog afaict (and the tag is missing in the repository).

@Cobrand
Copy link
Member

Cobrand commented Dec 27, 2023

This is coming from AudioFormat::from_ll(spec.format).unwrap(), which means that spec.format is not recognized.

Otherwise yes, we could avoid this panic by changing AudioSpec::convert_from_ll to return Result<AudioSpec, ()> instead of AudioSpec and panicking on unrecognized spec format.

@fschulze
Copy link
Author

I should add that this happens during enumeration of the audio devices. So it is likely that the format isn't known at that point.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants