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

Audio example crashes when an external audio device is selected on macOS #307

Closed
dvtkrlbs opened this issue Aug 23, 2020 · 13 comments
Closed
Assignees
Labels
A-Audio Sounds playback and modification O-MacOS Specific to the MacOS (Apple) desktop operating system P-Crash A sudden unexpected crash

Comments

@dvtkrlbs
Copy link

dvtkrlbs commented Aug 23, 2020

Like the title says app cant start when a different audio output device is selected (in my case when connected to an bluetooth headset) and also audio does not switch audio device when switch when the example is running. I would like to take a look at it and possibly fix it if someone can help me find my way. 😄
macOS version: macOS Catalina 10.15.3
Rust version: v1.47.0-nightly
Bevy commit hash: 022a31f
Here is the full backtrace:

Backtrace
thread '<unnamed>' panicked at 'No device name: BackendSpecific { err: BackendSpecificError { description: "core foundation unexpectedly returned null string" } }', /Users/dvtkrlbs/.cargo/registry/src/github.com-1ecc6299db9ec823/rodio-0.11.0/src/engine.rs:113:46
stack backtrace:
   0:        0x1061f3474 - std::backtrace_rs::backtrace::libunwind::trace::he9497f4525a08d2b
                               at /rustc/de521cbb303c08febd9fa3755caccd4f3e491ea3/library/std/src/../../backtrace/src/backtrace/libunwind.rs:96
   1:        0x1061f3474 - std::backtrace_rs::backtrace::trace_unsynchronized::h10a0a59d96f4a16b
                               at /rustc/de521cbb303c08febd9fa3755caccd4f3e491ea3/library/std/src/../../backtrace/src/backtrace/mod.rs:66
   2:        0x1061f3474 - std::sys_common::backtrace::_print_fmt::h6fd8fbf82b7783c5
                               at /rustc/de521cbb303c08febd9fa3755caccd4f3e491ea3/library/std/src/sys_common/backtrace.rs:79
   3:        0x1061f3474 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::hfb2db7374ccd4d34
                               at /rustc/de521cbb303c08febd9fa3755caccd4f3e491ea3/library/std/src/sys_common/backtrace.rs:58
   4:        0x1062162cc - core::fmt::write::h7e381316a10f5e82
                               at /rustc/de521cbb303c08febd9fa3755caccd4f3e491ea3/library/core/src/fmt/mod.rs:1117
   5:        0x1061ef87b - std::io::Write::write_fmt::h53862e22ed93af5e
                               at /rustc/de521cbb303c08febd9fa3755caccd4f3e491ea3/library/std/src/io/mod.rs:1514
   6:        0x1061f56f5 - std::sys_common::backtrace::_print::h5642011e0f38c919
                               at /rustc/de521cbb303c08febd9fa3755caccd4f3e491ea3/library/std/src/sys_common/backtrace.rs:61
   7:        0x1061f56f5 - std::sys_common::backtrace::print::hbcc5d5a374cdc250
                               at /rustc/de521cbb303c08febd9fa3755caccd4f3e491ea3/library/std/src/sys_common/backtrace.rs:48
   8:        0x1061f56f5 - std::panicking::default_hook::{{closure}}::h1a87f1c0565a051b
                               at /rustc/de521cbb303c08febd9fa3755caccd4f3e491ea3/library/std/src/panicking.rs:200
   9:        0x1061f5432 - std::panicking::default_hook::he29ab2038604c86f
                               at /rustc/de521cbb303c08febd9fa3755caccd4f3e491ea3/library/std/src/panicking.rs:219
  10:        0x1061f5c95 - std::panicking::rust_panic_with_hook::h9dab6d214201c5da
                               at /rustc/de521cbb303c08febd9fa3755caccd4f3e491ea3/library/std/src/panicking.rs:569
  11:        0x1061f582b - std::panicking::begin_panic_handler::{{closure}}::hf4bcec37fb7265f5
                               at /rustc/de521cbb303c08febd9fa3755caccd4f3e491ea3/library/std/src/panicking.rs:476
  12:        0x1061f38b8 - std::sys_common::backtrace::__rust_end_short_backtrace::h8c49942bd9c628f8
                               at /rustc/de521cbb303c08febd9fa3755caccd4f3e491ea3/library/std/src/sys_common/backtrace.rs:153
  13:        0x1061f57ea - rust_begin_unwind
                               at /rustc/de521cbb303c08febd9fa3755caccd4f3e491ea3/library/std/src/panicking.rs:475
  14:        0x10623a31f - core::panicking::panic_fmt::hc5e2a0be1d842c94
                               at /rustc/de521cbb303c08febd9fa3755caccd4f3e491ea3/library/core/src/panicking.rs:85
  15:        0x10623a225 - core::option::expect_none_failed::hc897e7630c12c4bc
                               at /rustc/de521cbb303c08febd9fa3755caccd4f3e491ea3/library/core/src/option.rs:1221
  16:        0x1058e6a6d - core::result::Result<T,E>::expect::h54fe71f921dad86d
                               at /Users/dvtkrlbs/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/library/core/src/result.rs:933
  17:        0x1058f76f9 - rodio::engine::start::h9ab40b78d75a38d9
                               at /Users/dvtkrlbs/.cargo/registry/src/github.com-1ecc6299db9ec823/rodio-0.11.0/src/engine.rs:113
  18:        0x1058f7d9c - rodio::engine::play_raw::h373a8781dcd573d6
                               at /Users/dvtkrlbs/.cargo/registry/src/github.com-1ecc6299db9ec823/rodio-0.11.0/src/engine.rs:54
  19:        0x1058fdc35 - rodio::sink::Sink::new::h17b88bfe9b701ea5
                               at /Users/dvtkrlbs/.cargo/registry/src/github.com-1ecc6299db9ec823/rodio-0.11.0/src/sink.rs:40
  20:        0x1058c3759 - bevy_audio::audio_output::AudioOutput::play_source::h2fccc2f881e12051
                               at /Users/dvtkrlbs/Desktop/DEV/temp/bevy/crates/bevy_audio/src/audio_output.rs:25
  21:        0x1058c3a4c - bevy_audio::audio_output::AudioOutput::try_play_queued::h8648abec926220ff
                               at /Users/dvtkrlbs/Desktop/DEV/temp/bevy/crates/bevy_audio/src/audio_output.rs:41
  22:        0x1058c3b07 - bevy_audio::audio_output::play_queued_audio_system::h2e3df69f7dfd0d67
                               at /Users/dvtkrlbs/Desktop/DEV/temp/bevy/crates/bevy_audio/src/audio_output.rs:56
  23:        0x1058dcc61 - core::ops::function::Fn::call::h2a06370897519d8d
                               at /Users/dvtkrlbs/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/library/core/src/ops/function.rs:72
  24:        0x1059037e4 - core::ops::function::impls::<impl core::ops::function::FnMut<A> for &F>::call_mut::h55f8597aed7a9d64
                               at /Users/dvtkrlbs/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/library/core/src/ops/function.rs:253
  25:        0x105906490 - <Func as bevy_ecs::system::into_system::IntoQuerySystem<(),(Ra,Rb),()>>::system::{{closure}}::h5030d15e70c1684a
                               at /Users/dvtkrlbs/Desktop/DEV/temp/bevy/crates/bevy_ecs/src/system/into_system.rs:186
  26:        0x105906e5f - <bevy_ecs::system::into_system::SystemFn<State,F,ThreadLocalF,Init,SetArchetypeAccess> as bevy_ecs::system::system::System>::run::h814c48000d252e61
                               at /Users/dvtkrlbs/Desktop/DEV/temp/bevy/crates/bevy_ecs/src/system/into_system.rs:61
  27:        0x1060eed34 - bevy_ecs::schedule::parallel_executor::ExecutorStage::run_ready_systems::{{closure}}::he6b5e0f88b25432b
                               at /Users/dvtkrlbs/Desktop/DEV/temp/bevy/crates/bevy_ecs/src/schedule/parallel_executor.rs:313
  28:        0x1060e1fb6 - rayon_core::scope::ScopeFifo::spawn_fifo::{{closure}}::{{closure}}::h99862228c85d6906
                               at /Users/dvtkrlbs/.cargo/registry/src/github.com-1ecc6299db9ec823/rayon-core-1.7.1/src/scope/mod.rs:496
  29:        0x106103f71 - <std::panic::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once::h51eff54bbb1ab351
                               at /Users/dvtkrlbs/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/library/std/src/panic.rs:308
  30:        0x1060e5f25 - std::panicking::try::do_call::h1a490228948c944a
                               at /Users/dvtkrlbs/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/library/std/src/panicking.rs:373
  31:        0x1060e638d - ___rust_try
  32:        0x1060e5ba1 - std::panicking::try::hae8cafc504756c5a
                               at /Users/dvtkrlbs/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/library/std/src/panicking.rs:337
  33:        0x106104091 - std::panic::catch_unwind::hcceb35a916471458
                               at /Users/dvtkrlbs/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/library/std/src/panic.rs:379
  34:        0x1060eba75 - rayon_core::unwind::halt_unwinding::h77279b1046653d4b
                               at /Users/dvtkrlbs/.cargo/registry/src/github.com-1ecc6299db9ec823/rayon-core-1.7.1/src/unwind.rs:17
  35:        0x1060e1969 - rayon_core::scope::ScopeBase::execute_job_closure::hc3719e544b170aa0
                               at /Users/dvtkrlbs/.cargo/registry/src/github.com-1ecc6299db9ec823/rayon-core-1.7.1/src/scope/mod.rs:562
  36:        0x1060e1805 - rayon_core::scope::ScopeBase::execute_job::ha60b34308e091148
                               at /Users/dvtkrlbs/.cargo/registry/src/github.com-1ecc6299db9ec823/rayon-core-1.7.1/src/scope/mod.rs:550
  37:        0x1060e1f5d - rayon_core::scope::ScopeFifo::spawn_fifo::{{closure}}::h0db2e29bba508a28
                               at /Users/dvtkrlbs/.cargo/registry/src/github.com-1ecc6299db9ec823/rayon-core-1.7.1/src/scope/mod.rs:496
  38:        0x1060f6aad - <rayon_core::job::HeapJob<BODY> as rayon_core::job::Job>::execute::h70e27cb232f071dc
                               at /Users/dvtkrlbs/.cargo/registry/src/github.com-1ecc6299db9ec823/rayon-core-1.7.1/src/job.rs:167
  39:        0x106118575 - rayon_core::job::JobRef::execute::h3209e7b6d2bdfa96
                               at /Users/dvtkrlbs/.cargo/registry/src/github.com-1ecc6299db9ec823/rayon-core-1.7.1/src/job.rs:59
  40:        0x10611867a - <rayon_core::job::JobFifo as rayon_core::job::Job>::execute::hbd9502b56141f397
                               at /Users/dvtkrlbs/.cargo/registry/src/github.com-1ecc6299db9ec823/rayon-core-1.7.1/src/job.rs:209
  41:        0x106118575 - rayon_core::job::JobRef::execute::h3209e7b6d2bdfa96
                               at /Users/dvtkrlbs/.cargo/registry/src/github.com-1ecc6299db9ec823/rayon-core-1.7.1/src/job.rs:59
  42:        0x1061094f4 - rayon_core::registry::WorkerThread::execute::he751cd3dc295e613
                               at /Users/dvtkrlbs/.cargo/registry/src/github.com-1ecc6299db9ec823/rayon-core-1.7.1/src/registry.rs:685
  43:        0x106235df0 - rayon_core::registry::WorkerThread::wait_until_cold::h08f42af814c65a3b
                               at /Users/dvtkrlbs/.cargo/registry/src/github.com-1ecc6299db9ec823/rayon-core-1.7.1/src/registry.rs:669
  44:        0x106109432 - rayon_core::registry::WorkerThread::wait_until::h425bd7b46f71bd82
                               at /Users/dvtkrlbs/.cargo/registry/src/github.com-1ecc6299db9ec823/rayon-core-1.7.1/src/registry.rs:643
  45:        0x106127035 - rayon_core::scope::ScopeBase::steal_till_jobs_complete::h3c71f57b243d9950
                               at /Users/dvtkrlbs/.cargo/registry/src/github.com-1ecc6299db9ec823/rayon-core-1.7.1/src/scope/mod.rs:605
  46:        0x1060e1b5c - rayon_core::scope::ScopeBase::complete::h96a4bb37c27ab438
                               at /Users/dvtkrlbs/.cargo/registry/src/github.com-1ecc6299db9ec823/rayon-core-1.7.1/src/scope/mod.rs:538
  47:        0x1060e16dc - rayon_core::scope::scope_fifo::{{closure}}::h5f903de42b29d8bb
                               at /Users/dvtkrlbs/.cargo/registry/src/github.com-1ecc6299db9ec823/rayon-core-1.7.1/src/scope/mod.rs:385
  48:        0x1060d35c7 - rayon_core::registry::Registry::in_worker_cold::{{closure}}::{{closure}}::h08e878b46f3439e9
                               at /Users/dvtkrlbs/.cargo/registry/src/github.com-1ecc6299db9ec823/rayon-core-1.7.1/src/registry.rs:447
  49:        0x1060f7071 - <rayon_core::job::StackJob<L,F,R> as rayon_core::job::Job>::execute::call::{{closure}}::h265df375dc735991
                               at /Users/dvtkrlbs/.cargo/registry/src/github.com-1ecc6299db9ec823/rayon-core-1.7.1/src/job.rs:113
  50:        0x106103eb1 - <std::panic::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once::h1add996b3d820643
                               at /Users/dvtkrlbs/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/library/std/src/panic.rs:308
  51:        0x1060e6075 - std::panicking::try::do_call::hb85ae2505f86dcf4
                               at /Users/dvtkrlbs/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/library/std/src/panicking.rs:373
  52:        0x1060e638d - ___rust_try
  53:        0x1060e5cf1 - std::panicking::try::hdbff4c17508b1ef5
                               at /Users/dvtkrlbs/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/library/std/src/panicking.rs:337
  54:        0x106103ff1 - std::panic::catch_unwind::h15268196a3d8fcdd
                               at /Users/dvtkrlbs/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/library/std/src/panic.rs:379
  55:        0x1060eb965 - rayon_core::unwind::halt_unwinding::h48dbd77d8d8530d6
                               at /Users/dvtkrlbs/.cargo/registry/src/github.com-1ecc6299db9ec823/rayon-core-1.7.1/src/unwind.rs:17
  56:        0x1060f6bb5 - <rayon_core::job::StackJob<L,F,R> as rayon_core::job::Job>::execute::ha551aed8c0328da2
                               at /Users/dvtkrlbs/.cargo/registry/src/github.com-1ecc6299db9ec823/rayon-core-1.7.1/src/job.rs:119
  57:        0x106118575 - rayon_core::job::JobRef::execute::h3209e7b6d2bdfa96
                               at /Users/dvtkrlbs/.cargo/registry/src/github.com-1ecc6299db9ec823/rayon-core-1.7.1/src/job.rs:59
  58:        0x1061094f4 - rayon_core::registry::WorkerThread::execute::he751cd3dc295e613
                               at /Users/dvtkrlbs/.cargo/registry/src/github.com-1ecc6299db9ec823/rayon-core-1.7.1/src/registry.rs:685
  59:        0x106235df0 - rayon_core::registry::WorkerThread::wait_until_cold::h08f42af814c65a3b
                               at /Users/dvtkrlbs/.cargo/registry/src/github.com-1ecc6299db9ec823/rayon-core-1.7.1/src/registry.rs:669
  60:        0x106109432 - rayon_core::registry::WorkerThread::wait_until::h425bd7b46f71bd82
                               at /Users/dvtkrlbs/.cargo/registry/src/github.com-1ecc6299db9ec823/rayon-core-1.7.1/src/registry.rs:643
  61:        0x106109cd6 - rayon_core::registry::main_loop::h9c2dee66eeee11fa
                               at /Users/dvtkrlbs/.cargo/registry/src/github.com-1ecc6299db9ec823/rayon-core-1.7.1/src/registry.rs:763
  62:        0x106107200 - rayon_core::registry::ThreadBuilder::run::h606318204a408b28
                               at /Users/dvtkrlbs/.cargo/registry/src/github.com-1ecc6299db9ec823/rayon-core-1.7.1/src/registry.rs:56
  63:        0x1061076c1 - <rayon_core::registry::DefaultSpawn as rayon_core::registry::ThreadSpawn>::spawn::{{closure}}::hd1d690f8ac8b0501
                               at /Users/dvtkrlbs/.cargo/registry/src/github.com-1ecc6299db9ec823/rayon-core-1.7.1/src/registry.rs:101
  64:        0x1061157c0 - std::sys_common::backtrace::__rust_begin_short_backtrace::h20ceeb21e12ceba9
                               at /Users/dvtkrlbs/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/library/std/src/sys_common/backtrace.rs:137
  65:        0x106120091 - std::thread::Builder::spawn_unchecked::{{closure}}::{{closure}}::heec5c0d1f4bc1391
                               at /Users/dvtkrlbs/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/library/std/src/thread/mod.rs:458
  66:        0x106124044 - <std::panic::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once::hb01d2ad5ff9a17e5
                               at /Users/dvtkrlbs/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/library/std/src/panic.rs:308
  67:        0x10610f8d5 - std::panicking::try::do_call::h7a1d8cad5cb14dd1
                               at /Users/dvtkrlbs/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/library/std/src/panicking.rs:373
  68:        0x106110f0d - ___rust_try
  69:        0x10610f771 - std::panicking::try::h913d517abe77777b
                               at /Users/dvtkrlbs/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/library/std/src/panicking.rs:337
  70:        0x1061243a4 - std::panic::catch_unwind::h85d0fa8efbbfc30b
                               at /Users/dvtkrlbs/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/library/std/src/panic.rs:379
  71:        0x10611fed8 - std::thread::Builder::spawn_unchecked::{{closure}}::h990e14ab60750507
                               at /Users/dvtkrlbs/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/library/std/src/thread/mod.rs:457
  72:        0x106115a31 - core::ops::function::FnOnce::call_once{{vtable.shim}}::hee7b01597c35d95f
                               at /Users/dvtkrlbs/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/library/core/src/ops/function.rs:233
  73:        0x1061fc81d - <alloc::boxed::Box<F> as core::ops::function::FnOnce<A>>::call_once::h85dfeaba80b7a665
                               at /rustc/de521cbb303c08febd9fa3755caccd4f3e491ea3/library/alloc/src/boxed.rs:1025
  74:        0x1061fc81d - <alloc::boxed::Box<F> as core::ops::function::FnOnce<A>>::call_once::h05752f0c5860f139
                               at /rustc/de521cbb303c08febd9fa3755caccd4f3e491ea3/library/alloc/src/boxed.rs:1025
  75:        0x1061fc81d - std::sys::unix::thread::Thread::new::thread_start::h39b071b0d2fb7aea
                               at /rustc/de521cbb303c08febd9fa3755caccd4f3e491ea3/library/std/src/sys/unix/thread.rs:87
  76:     0x7fff72d63e65 - __pthread_start
@dvtkrlbs
Copy link
Author

Following the rabbit hole it seems it might be an issue with the rodio library apperantly it panics at an expect block since it cannot get the name of the device. Looking at the repo they made some rework with the crate and also removing the engine system completely. I will try to use the git version of rodio and see if it fixes the issue.

@GabCampbell GabCampbell added the P-Crash A sudden unexpected crash label Aug 23, 2020
@GabCampbell
Copy link
Contributor

@dvtkrlbs are you comfortable with me assigning this issue to you?

@dvtkrlbs
Copy link
Author

Yeah that is okay

@GabCampbell
Copy link
Contributor

@dvtkrlbs thanks!

@dvtkrlbs
Copy link
Author

Tried it with the rodio git version as well it looks like rodio can't get a default device when an output device is selected within the macOS menu. Should i open an issue on rodio or should i go deeper to see if it is an issue with cpal ?

@GabCampbell
Copy link
Contributor

@dvtkrlbs do you have an opinion on the best course of action here?

@dvtkrlbs
Copy link
Author

dvtkrlbs commented Aug 23, 2020

I have no idea. I can't say anything before seeing any reproduce of the same bug. Since it may be a problem with my own system. But it looks like cpal (the library that rodio uses to interact with audio devices) seems to to cannot get a default device. So it is beyond our reach to fix.

Edit: Wrote on the bevy discord to see if anyone tries it and also try to reproduce the issue with rodio alone. If i am succesful i will open an issue on rodio github page to ask for further help.

@dvtkrlbs
Copy link
Author

dvtkrlbs commented Aug 23, 2020

I tried it with rodio alone with master branch and it worked. I think there is an issue with the sink but i am still investigating. Sink works too with master branch it still does not switch audio device automatically but no panic. So we can either wait for the next rodio release or we can use the master branch.

@dvtkrlbs
Copy link
Author

dvtkrlbs commented Aug 23, 2020

It seems it works with the rodio master branch. But the problem is rodio got rid of the device concept fully and now they give you an OutputStream and an OutputStremHandle and OutputStream is not Send + Sync. In my proof of concept i just do std::mem::forget on the OutputStream but we need to store and normally destroy OutputStream somewhere (if dropped the handle does not work)

@karroffel karroffel added A-Audio Sounds playback and modification O-MacOS Specific to the MacOS (Apple) desktop operating system labels Aug 24, 2020
@dvtkrlbs
Copy link
Author

dvtkrlbs commented Oct 6, 2020

The new version of rodio has been published to crates.io

@Weibye
Copy link
Contributor

Weibye commented Aug 16, 2021

Has the issue been fixed by #638 #692? Should the issue be closed?

@dvtkrlbs
Copy link
Author

I havent been able to test it.

@rparrett
Copy link
Contributor

rparrett commented Sep 13, 2023

I was able to

  • reproduce the issue with rodio 0.11
  • verify that rodio 0.12 fixed it
  • and that audio continues to work with a bluetooth headset on macos with the latest Bevy (rodio 0.17).

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 O-MacOS Specific to the MacOS (Apple) desktop operating system P-Crash A sudden unexpected crash
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

5 participants