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

Bevy crashes when not found any audio device #850

Closed
qarmin opened this issue Nov 12, 2020 · 13 comments
Closed

Bevy crashes when not found any audio device #850

qarmin opened this issue Nov 12, 2020 · 13 comments
Labels
A-Audio Sounds playback and modification P-Crash A sudden unexpected crash

Comments

@qarmin
Copy link

qarmin commented Nov 12, 2020

Bevy version

Operating system & version
Ubuntu 20.10 docker

What you did

I wanted to run bevy inside ubuntu docker image

What you expected to happen

App should open properly

What actually happened
This error was shown and later crash happens

ALSA lib confmisc.c:767:(parse_card) cannot find card '0'
ALSA lib conf.c:4743:(_snd_config_evaluate) function snd_func_card_driver returned error: No such file or directory
ALSA lib confmisc.c:392:(snd_func_concat) error evaluating strings
ALSA lib conf.c:4743:(_snd_config_evaluate) function snd_func_concat returned error: No such file or directory
ALSA lib confmisc.c:1246:(snd_func_refer) error evaluating name
ALSA lib conf.c:4743:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory
ALSA lib conf.c:5231:(snd_config_expand) Evaluate error: No such file or directory
ALSA lib pcm.c:2660:(snd_pcm_open_noupdate) Unknown PCM default
thread 'main' panicked at 'The device doesn't support any format!?: DeviceNotAvailable', /root/.cargo/registry/src/jackfan.us.kg-1ecc6299db9ec823/rodio-0.13.0/src/stream.rs:191:30
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Additional information
When not found audio device, bevy shouldn't crash but only show error - RustAudio/rodio#334

Steps to reproduce

  • Open 20.10 docker image
  • Install xvfb apt install xvfb
  • Download and compile Mesa from source and install it (it contains LavaPipe, which allow to run Vulkan app in CI)
  • Clone Bevy
  • cargo run --example clear_color (it is a little strange that this example needs audio)
  • xvfb-run target/debug/examples/clear_color
@Moxinilian Moxinilian added A-Audio Sounds playback and modification P-Crash A sudden unexpected crash labels Nov 12, 2020
@castarco
Copy link

castarco commented Nov 13, 2020

Can you provide a minimal code example? I guess that for Bevy developers it's probably quite straightforward to find the problem source, but I'm curious about what are the plugins involved.

Before continuing, I'm using Bevy v0.3, on Ubuntu 20.04, without docker or anything like that.

I actually came here to write about another less problematic bug, but probably related. When I use DefaultPlugins (but not with MinimalPlugins), I get this error message (although without crashing the process), and I don't do anything with the sound:

thread '<unnamed>' panicked at 'attempt to multiply with overflow', /home/castarco/.cargo/registry/src/jackfan.us.kg-1ecc6299db9ec823/cpal-0.13.1/src/host/alsa/mod.rs:692:23
stack backtrace:
   0: rust_begin_unwind
             at /rustc/18bf6b4f01a6feaf7259ba7cdae58031af1b7b39/library/std/src/panicking.rs:475
   1: core::panicking::panic_fmt
             at /rustc/18bf6b4f01a6feaf7259ba7cdae58031af1b7b39/library/core/src/panicking.rs:85
   2: core::panicking::panic
             at /rustc/18bf6b4f01a6feaf7259ba7cdae58031af1b7b39/library/core/src/panicking.rs:50
   3: cpal::host::alsa::poll_descriptors_and_prepare_buffer
             at /home/castarco/.cargo/registry/src/jackfan.us.kg-1ecc6299db9ec823/cpal-0.13.1/src/host/alsa/mod.rs:692
   4: cpal::host::alsa::output_stream_worker
             at /home/castarco/.cargo/registry/src/jackfan.us.kg-1ecc6299db9ec823/cpal-0.13.1/src/host/alsa/mod.rs:548
   5: cpal::host::alsa::Stream::new_output::{{closure}}
             at /home/castarco/.cargo/registry/src/jackfan.us.kg-1ecc6299db9ec823/cpal-0.13.1/src/host/alsa/mod.rs:870
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

This is another panic message that appears when I try to terminate the program by closing its window (instead of typing Ctrl+C on the command line, which does not trigger it):

thread 'main' panicked at 'assertion failed: ret == 8', /home/castarco/.cargo/registry/src/jackfan.us.kg-1ecc6299db9ec823/cpal-0.13.1/src/host/alsa/mod.rs:130:9
stack backtrace:
   0: std::panicking::begin_panic
             at /home/castarco/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/panicking.rs:497
   1: cpal::host::alsa::TriggerSender::wakeup
             at /home/castarco/.cargo/registry/src/jackfan.us.kg-1ecc6299db9ec823/cpal-0.13.1/src/host/alsa/mod.rs:130
   2: <cpal::host::alsa::Stream as core::ops::drop::Drop>::drop
             at /home/castarco/.cargo/registry/src/jackfan.us.kg-1ecc6299db9ec823/cpal-0.13.1/src/host/alsa/mod.rs:882
   3: core::ptr::drop_in_place
             at /home/castarco/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ptr/mod.rs:184
   4: core::ptr::drop_in_place
             at /home/castarco/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ptr/mod.rs:184
   5: core::ptr::drop_in_place
             at /home/castarco/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ptr/mod.rs:184
   6: core::ptr::drop_in_place
             at /home/castarco/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ptr/mod.rs:184
   7: core::ptr::drop_in_place
             at /home/castarco/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ptr/mod.rs:184
   8: core::ptr::drop_in_place
             at /home/castarco/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ptr/mod.rs:184
   9: core::ptr::drop_in_place
             at /home/castarco/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ptr/mod.rs:184
  10: core::ptr::drop_in_place
             at /home/castarco/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ptr/mod.rs:184
  11: <alloc::vec::Vec<T> as core::ops::drop::Drop>::drop
             at /home/castarco/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/alloc/src/vec.rs:2447
  12: core::ptr::drop_in_place
             at /home/castarco/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ptr/mod.rs:184
  13: core::ptr::drop_in_place
             at /home/castarco/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ptr/mod.rs:184
  14: core::ptr::drop_in_place
             at /home/castarco/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ptr/mod.rs:184
  15: core::ptr::drop_in_place
             at /home/castarco/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ptr/mod.rs:184
  16: core::ptr::mut_ptr::<impl *mut T>::drop_in_place
             at /home/castarco/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ptr/mut_ptr.rs:963
  17: hashbrown::raw::Bucket<T>::drop
             at /cargo/registry/src/jackfan.us.kg-1ecc6299db9ec823/hashbrown-0.8.2/src/raw/mod.rs:334
  18: <hashbrown::raw::RawTable<T> as core::ops::drop::Drop>::drop
             at /cargo/registry/src/jackfan.us.kg-1ecc6299db9ec823/hashbrown-0.8.2/src/raw/mod.rs:1292
  19: core::ptr::drop_in_place
             at /home/castarco/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ptr/mod.rs:184
  20: core::ptr::drop_in_place
             at /home/castarco/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ptr/mod.rs:184
  21: core::ptr::drop_in_place
             at /home/castarco/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ptr/mod.rs:184
  22: core::ptr::drop_in_place
             at /home/castarco/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ptr/mod.rs:184
  23: core::ptr::drop_in_place
             at /home/castarco/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ptr/mod.rs:184
  24: core::ptr::drop_in_place
             at /home/castarco/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ptr/mod.rs:184
  25: winit::platform_impl::platform::x11::EventLoop<T>::run_return
             at /home/castarco/.cargo/registry/src/jackfan.us.kg-1ecc6299db9ec823/winit-0.23.0/src/platform_impl/linux/x11/mod.rs:380
  26: winit::platform_impl::platform::x11::EventLoop<T>::run
             at /home/castarco/.cargo/registry/src/jackfan.us.kg-1ecc6299db9ec823/winit-0.23.0/src/platform_impl/linux/x11/mod.rs:386
  27: winit::platform_impl::platform::EventLoop<T>::run
             at /home/castarco/.cargo/registry/src/jackfan.us.kg-1ecc6299db9ec823/winit-0.23.0/src/platform_impl/linux/mod.rs:642
  28: winit::event_loop::EventLoop<T>::run
             at /home/castarco/.cargo/registry/src/jackfan.us.kg-1ecc6299db9ec823/winit-0.23.0/src/event_loop.rs:154
  29: bevy_winit::run
             at /home/castarco/.cargo/registry/src/jackfan.us.kg-1ecc6299db9ec823/bevy_winit-0.3.0/src/lib.rs:105
  30: bevy_winit::winit_runner
             at /home/castarco/.cargo/registry/src/jackfan.us.kg-1ecc6299db9ec823/bevy_winit-0.3.0/src/lib.rs:300
  31: core::ops::function::Fn::call
             at /home/castarco/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ops/function.rs:70
  32: <alloc::boxed::Box<F> as core::ops::function::Fn<A>>::call
             at /home/castarco/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/alloc/src/boxed.rs:1056
  33: bevy_app::app::App::run
             at /home/castarco/.cargo/registry/src/jackfan.us.kg-1ecc6299db9ec823/bevy_app-0.3.0/src/app.rs:81
  34: bevy_app::app_builder::AppBuilder::run
             at /home/castarco/.cargo/registry/src/jackfan.us.kg-1ecc6299db9ec823/bevy_app-0.3.0/src/app_builder.rs:43
  35: mist_chess::main
             at ./src/main.rs:62
  36: core::ops::function::FnOnce::call_once
             at /home/castarco/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ops/function.rs:227
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

@iwikal
Copy link
Contributor

iwikal commented Nov 18, 2020

This happened to me as well. I had ALSA configured to use a sound card that wasn't connected. I would be very surprised if the minimal example isn't just using the AudioPlugin.

@k-brk
Copy link

k-brk commented Nov 26, 2020

I encountered same panic lately when I was trying out Bevy. I'm using Bevy v0.3 on Arch 5.8.12-arch1-1 without docker, I'm able to reproduce it every time with following minimal example(AudioPlugin alone is enough to cause this but we will get other panics without rest of plugins). It happens when we do not have default sound card set.

Minimal code example
use bevy::{asset::AssetPlugin, audio::AudioPlugin,core::CorePlugin, type_registry::TypeRegistryPlugin, prelude::*};

fn main() {
    App::build()
    .add_plugin(TypeRegistryPlugin::default())
    .add_plugin(CorePlugin::default())
    .add_plugin(AssetPlugin::default())
    .add_plugin(AudioPlugin::default())
    .run();
}
Backtrace
ALSA lib pcm_dmix.c:1090:(snd_pcm_dmix_open) unable to open slave
thread 'main' panicked at 'The device doesn't support any format!?: DeviceNotAvailable', /home/ja/.cargo/registry/src/jackfan.us.kg-1ecc6299db9ec823/rodio-0.13.0/src/stream.rs:193:14
stack backtrace:
   0: rust_begin_unwind
             at /rustc/18bf6b4f01a6feaf7259ba7cdae58031af1b7b39/library/std/src/panicking.rs:475
   1: core::panicking::panic_fmt
             at /rustc/18bf6b4f01a6feaf7259ba7cdae58031af1b7b39/library/core/src/panicking.rs:85
   2: core::option::expect_none_failed
             at /rustc/18bf6b4f01a6feaf7259ba7cdae58031af1b7b39/library/core/src/option.rs:1221
   3: core::result::Result<T,E>::expect
             at /home/ja/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/result.rs:933
   4: <cpal::platform::platform_impl::Device as rodio::stream::CpalDeviceExt>::new_output_stream
             at /home/ja/.cargo/registry/src/jackfan.us.kg-1ecc6299db9ec823/rodio-0.13.0/src/stream.rs:191
   5: rodio::stream::OutputStream::try_from_device
             at /home/ja/.cargo/registry/src/jackfan.us.kg-1ecc6299db9ec823/rodio-0.13.0/src/stream.rs:32
   6: rodio::stream::OutputStream::try_default
             at /home/ja/.cargo/registry/src/jackfan.us.kg-1ecc6299db9ec823/rodio-0.13.0/src/stream.rs:46
   7: <bevy_audio::audio_output::AudioOutput<P> as core::default::Default>::default
             at /home/ja/.cargo/registry/src/jackfan.us.kg-1ecc6299db9ec823/bevy_audio-0.3.0/src/audio_output.rs:22
   8: <T as bevy_ecs::resource::resources::FromResources>::from_resources
             at /home/ja/.cargo/registry/src/jackfan.us.kg-1ecc6299db9ec823/bevy_ecs-0.3.0/src/resource/resources.rs:401
   9: bevy_app::app_builder::AppBuilder::init_thread_local_resource
             at /home/ja/.cargo/registry/src/jackfan.us.kg-1ecc6299db9ec823/bevy_app-0.3.0/src/app_builder.rs:255
  10: <bevy_audio::AudioPlugin as bevy_app::plugin::Plugin>::build
             at /home/ja/.cargo/registry/src/jackfan.us.kg-1ecc6299db9ec823/bevy_audio-0.3.0/src/lib.rs:23
  11: bevy_app::app_builder::AppBuilder::add_plugin
             at /home/ja/.cargo/registry/src/jackfan.us.kg-1ecc6299db9ec823/bevy_app-0.3.0/src/app_builder.rs:271
  12: bevy_game::main
             at ./src/main.rs:4
  13: core::ops::function::FnOnce::call_once
             at /home/ja/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ops/function.rs:227
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
It panics on following unwrap:

let (stream, stream_handle) = OutputStream::try_default().unwrap();

Workaround for this issue on Arch is to set default sound card ( https://wiki.archlinux.org/index.php/Advanced_Linux_Sound_Architecture#Set_the_default_sound_card ), tried setting sound card order via kernel module and it solves issue.

@VictorAlbertsson
Copy link

I'm running Arch and also have this issue however I can't seem to fix it, maybe my ALSA setup is completely broken and I haven't noticed it until now (everything except this is working fine) or a more in-depth solution would be appreciated.

@samuel-cavalcanti
Copy link

I'm a arch user to and have the same issue, I following the getting started tutorial when this happens

https://bevyengine.org/learn/book/getting-started/plugins/
my code:

   App::build()
        .add_plugins(DefaultPlugins)
        .add_startup_system(add_people.system())
        .add_system(hello_world.system())
        .add_system(greet_people.system())
        .run();

OBS: i installed the dependencies libx11 pkgconf alsa-lib

@norman784
Copy link

Installing pulseaudio-alsa fixed the issue for me.

@samuel-cavalcanti
Copy link

Installing pulseaudio-alsa fixed the issue for me.

I have pulseaudio-alsa installed, for me it's not work 😭

@norman784
Copy link

Workaround for this issue on Arch is to set default sound card ( https://wiki.archlinux.org/index.php/Advanced_Linux_Sound_Architecture#Set_the_default_sound_card ), tried setting sound card order via kernel module and it solves issue.

@samuel-cavalcanti I'm not sure if following the guide above helped too, because I first tried to add the /etc/asound.conf and /etc/modprobe.d/alsa-base.conf files, after that I restarted and lastly I installed the pulseaudio-alsa package.

@samuel-cavalcanti
Copy link

Wtf ?! reinstalling the package works .
Thank you @norman784 , I do not know why, but adding the config in ~.asound.conf and reinstalling the pulseaudio-alsa works for me.
Someone can put this information in docs/linux_dependencies.md , helps a lot

@unknownue
Copy link
Contributor

unknownue commented Jan 12, 2021

I work out a solution for ubuntu container (20.04) without audio device:

  1. Inside container, Install audio package by: apt install -y pulseaudio
  2. Set audio source as described in here, to be specific:
    1. Give audio access to current user: adduser $(id -u -n) pulse-access
    2. rm -rf /var/run/pulse /var/lib/pulse /root/.config/pulse
    3. pulseaudio -D --verbose --exit-idle-time=-1 --system --disallow-exit
  3. Run your problem: cargo run

@visualcode-t
Copy link

I have noticed this same issue on many different machines. I don't think this is as much a driver issue as it is a problem that should be addressed with Bevy. Bevy should opt out of audio before crashing, or at least, it should allow the developer to make this decision. Many applications and even games are fine without audio and a developer shouldn't have to offer two versions of a program (one with and one without audio dependencies).

I know there has been discussion to change the audio system in Bevy, perhaps this should be addressed there? @Moxinilian @Dash-L

@cart
Copy link
Member

cart commented Feb 9, 2021

Yeah I agree that Bevy shouldn't crash in this case. Ideally it just displays an error message when a device can't be found (and probably when audio is played but no device is available). Additionally, it would be great if it could gracefully respond to devices being connected / defaults being switched.

@forbjok
Copy link
Contributor

forbjok commented May 28, 2021

This issue is present in Windows as well, although the error message is different.

thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: NoDevice', C:\Users\forbjok\.cargo\registry\src\jackfan.us.kg-1ecc6299db9ec823\bevy_audio-0.5.0\src\audio_output.rs:22:67

While it's probably not super common to not have an audio device, it definitely should not cause a crash.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Audio Sounds playback and modification P-Crash A sudden unexpected crash
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.