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

Rodio doesn't work with piston_window on Windows 10 due to incompatible thread modes #374

Closed
Herohtar opened this issue Jun 17, 2021 · 2 comments

Comments

@Herohtar
Copy link

I'm not sure which package is "at fault" or has the ability to resolve the issue, but rodio no longer plays nice with piston_window. Here's the minimal code necessary to reproduce:

Cargo.toml

[package]
name = "piston-rodio"
version = "0.1.0"
edition = "2018"

[dependencies]
piston_window = "0.120.0"
rodio = "0.14.0"

main.rs

use piston_window::*;
use rodio::OutputStream;

fn main() {
    let (_stream, _stream_handle) = OutputStream::try_default().unwrap();
    let mut window: PistonWindow = WindowSettings::new("Hello World!", [512; 2]).build().unwrap();

    while let Some(e) = window.next() {
        window.draw_2d(&e, |c, g, _device| {
            clear([1.; 4], g);
            rectangle([1., 0., 0., 1.], [100., 100., 100., 100.], c.transform, g);
        });
    }
}

Stack trace

     Running `target\debug\piston-rodio.exe`
thread 'main' panicked at 'OleInitialize failed! Result was: `RPC_E_CHANGED_MODE`. Make sure other crates are not using multithreaded COM library on the same thread or disable drag and drop support.', C:\Users\heroh\.cargo\registry\src\github.com-1ecc6299db9ec823\winit-0.24.0\src\platform_impl\windows\window.rs:85:25
stack backtrace:
   0: std::panicking::begin_panic<str>
             at C:\Users\heroh\.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\std\src\panicking.rs:519
   1: winit::platform_impl::platform::window::{{impl}}::new::{{closure}}<glutin_window::UserEvent>
             at C:\Users\heroh\.cargo\registry\src\github.com-1ecc6299db9ec823\winit-0.24.0\src\platform_impl\windows\window.rs:85
   2: core::result::Result<winit::platform_impl::platform::window::Window, winit::error::OsError>::map<winit::platform_impl::platform::window::Window,winit::error::OsError,winit::platform_impl::platform::window::Window,closure-0>
             at C:\Users\heroh\.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\core\src\result.rs:504
   3: winit::platform_impl::platform::window::Window::new<glutin_window::UserEvent>
             at C:\Users\heroh\.cargo\registry\src\github.com-1ecc6299db9ec823\winit-0.24.0\src\platform_impl\windows\window.rs:75
   4: winit::window::WindowBuilder::build<glutin_window::UserEvent>
             at C:\Users\heroh\.cargo\registry\src\github.com-1ecc6299db9ec823\winit-0.24.0\src\window.rs:333
   5: glutin::platform_impl::platform_impl::Context::new_windowed<glutin_window::UserEvent>      
             at C:\Users\heroh\.cargo\registry\src\github.com-1ecc6299db9ec823\glutin-0.26.0\src\platform_impl\windows\mod.rs:53
   6: glutin::ContextBuilder<glutin::context::NotCurrent>::build_windowed<glutin::context::NotCurrent,glutin_window::UserEvent>
             at C:\Users\heroh\.cargo\registry\src\github.com-1ecc6299db9ec823\glutin-0.26.0\src\windowed.rs:341
   7: glutin_window::GlutinWindow::new
             at C:\Users\heroh\.cargo\registry\src\github.com-1ecc6299db9ec823\pistoncore-glutin_window-0.69.0\src\lib.rs:124
   8: glutin_window::{{impl}}::build_from_window_settings
             at C:\Users\heroh\.cargo\registry\src\github.com-1ecc6299db9ec823\pistoncore-glutin_window-0.69.0\src\lib.rs:541
   9: window::WindowSettings::build<glutin_window::GlutinWindow>
             at C:\Users\heroh\.cargo\registry\src\github.com-1ecc6299db9ec823\pistoncore-window-0.47.0\src\lib.rs:467
  10: piston_window::{{impl}}::build_from_window_settings<glutin_window::GlutinWindow>
             at C:\Users\heroh\.cargo\registry\src\github.com-1ecc6299db9ec823\piston_window-0.120.0\src\lib.rs:191
  11: window::WindowSettings::build<piston_window::PistonWindow<glutin_window::GlutinWindow>>    
             at C:\Users\heroh\.cargo\registry\src\github.com-1ecc6299db9ec823\pistoncore-window-0.47.0\src\lib.rs:467
  12: piston_rodio::main
             at .\src\main.rs:6
  13: core::ops::function::FnOnce::call_once<fn(),tuple<>>
             at C:\Users\heroh\.rustup\toolchains\stable-x86_64-pc-windows-msvc\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.
error: process didn't exit successfully: `target\debug\piston-rodio.exe` (exit code: 101)

Alternative stack trace

This is the stack trace that results from swapping lines 5 and 6 in the example code so that PistonWindow is initialized before OutputStream:

     Running `target\debug\piston-rodio.exe`
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Os { code: -2147417850, kind: Other, message: "Cannot change thread mode after it is set." }', C:\Users\heroh\.cargo\registry\src\github.com-1ecc6299db9ec823\cpal-0.13.3\src\host\wasapi\com.rs:13:77
stack backtrace:
   0: std::panicking::begin_panic_handler
             at /rustc/9bc8c42bb2f19e745a63f3445f1ac248fb015e53\/library\std\src\panicking.rs:493   1: core::panicking::panic_fmt
             at /rustc/9bc8c42bb2f19e745a63f3445f1ac248fb015e53\/library\core\src\panicking.rs:92   2: core::option::expect_none_failed
             at /rustc/9bc8c42bb2f19e745a63f3445f1ac248fb015e53\/library\core\src\option.rs:1329 
   3: core::result::Result<tuple<>, std::io::error::Error>::unwrap<tuple<>,std::io::error::Error>             at C:\Users\heroh\.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\core\src\result.rs:1037
   4: cpal::host::wasapi::com::COM_INITIALIZED::__init
             at C:\Users\heroh\.cargo\registry\src\github.com-1ecc6299db9ec823\cpal-0.13.3\src\host\wasapi\com.rs:13
   5: core::ops::function::FnOnce::call_once<fn() -> cpal::host::wasapi::com::ComInitialized,tuple<>>
             at C:\Users\heroh\.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\core\src\ops\function.rs:227
   6: std::thread::local::lazy::LazyKeyInner<cpal::host::wasapi::com::ComInitialized>::initialize<cpal::host::wasapi::com::ComInitialized,fn() -> cpal::host::wasapi::com::ComInitialized>        
             at C:\Users\heroh\.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\std\src\thread\local.rs:304
   7: std::thread::local::fast::Key<cpal::host::wasapi::com::ComInitialized>::try_initialize<cpal::host::wasapi::com::ComInitialized,fn() -> cpal::host::wasapi::com::ComInitialized>
             at C:\Users\heroh\.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\std\src\thread\local.rs:473
   8: std::thread::local::fast::Key<cpal::host::wasapi::com::ComInitialized>::get<cpal::host::wasapi::com::ComInitialized,fn() -> cpal::host::wasapi::com::ComInitialized>
             at C:\Users\heroh\.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\std\src\thread\local.rs:456
   9: cpal::host::wasapi::com::COM_INITIALIZED::__getit
             at C:\Users\heroh\.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\std\src\thread\local.rs:183
  10: std::thread::local::LocalKey<cpal::host::wasapi::com::ComInitialized>::try_with<cpal::host::wasapi::com::ComInitialized,closure-0,tuple<>>
             at C:\Users\heroh\.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\std\src\thread\local.rs:271
  11: std::thread::local::LocalKey<cpal::host::wasapi::com::ComInitialized>::with<cpal::host::wasapi::com::ComInitialized,closure-0,tuple<>>
             at C:\Users\heroh\.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\std\src\thread\local.rs:248
  12: cpal::host::wasapi::com::com_initialized
             at C:\Users\heroh\.cargo\registry\src\github.com-1ecc6299db9ec823\cpal-0.13.3\src\host\wasapi\com.rs:34
  13: core::ops::function::FnOnce::call_once<fn() -> cpal::host::wasapi::device::Enumerator,tuple<>>
             at C:\Users\heroh\.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\core\src\ops\function.rs:227
  14: lazy_static::lazy::{{impl}}::get::{{closure}}<cpal::host::wasapi::device::Enumerator,fn() -> cpal::host::wasapi::device::Enumerator>
             at C:\Users\heroh\.cargo\registry\src\github.com-1ecc6299db9ec823\lazy_static-1.4.0\src\inline_lazy.rs:31
  15: std::sync::once::{{impl}}::call_once::{{closure}}<closure-0>
             at C:\Users\heroh\.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\std\src\sync\once.rs:261
  16: std::sync::once::Once::call_inner
             at /rustc/9bc8c42bb2f19e745a63f3445f1ac248fb015e53\/library\std\src\sync\once.rs:418  17: std::sync::once::Once::call_once<closure-0>
             at C:\Users\heroh\.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\std\src\sync\once.rs:261
  18: lazy_static::lazy::Lazy<cpal::host::wasapi::device::Enumerator>::get
             at C:\Users\heroh\.cargo\registry\src\github.com-1ecc6299db9ec823\lazy_static-1.4.0\src\inline_lazy.rs:30
  19: cpal::host::wasapi::device::{{impl}}::deref::__stability
             at C:\Users\heroh\.cargo\registry\src\github.com-1ecc6299db9ec823\lazy_static-1.4.0\src\lib.rs:142
  20: cpal::host::wasapi::device::{{impl}}::deref
             at C:\Users\heroh\.cargo\registry\src\github.com-1ecc6299db9ec823\lazy_static-1.4.0\src\lib.rs:144
  21: cpal::host::wasapi::device::default_device
             at C:\Users\heroh\.cargo\registry\src\github.com-1ecc6299db9ec823\cpal-0.13.3\src\host\wasapi\device.rs:1182
  22: cpal::host::wasapi::device::default_output_device
             at C:\Users\heroh\.cargo\registry\src\github.com-1ecc6299db9ec823\cpal-0.13.3\src\host\wasapi\device.rs:1195
  23: cpal::host::wasapi::{{impl}}::default_output_device
             at C:\Users\heroh\.cargo\registry\src\github.com-1ecc6299db9ec823\cpal-0.13.3\src\host\wasapi\mod.rs:50
  24: cpal::platform::platform_impl::{{impl}}::default_output_device
             at C:\Users\heroh\.cargo\registry\src\github.com-1ecc6299db9ec823\cpal-0.13.3\src\platform\mod.rs:343
  25: rodio::stream::OutputStream::try_default
             at C:\Users\heroh\.cargo\registry\src\github.com-1ecc6299db9ec823\rodio-0.14.0\src\stream.rs:44
  26: piston_rodio::main
             at .\src\main.rs:6
  27: core::ops::function::FnOnce::call_once<fn(),tuple<>>
             at C:\Users\heroh\.rustup\toolchains\stable-x86_64-pc-windows-msvc\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.
error: process didn't exit successfully: `target\debug\piston-rodio.exe` (exit code: 101)
@lukors
Copy link

lukors commented Aug 8, 2021

Seems like this recent merge might fix this? RustAudio/cpal#597

@est31
Copy link
Member

est31 commented Aug 8, 2021

Seems like it! @Herohtar If you feel otherwise, please comment.

@est31 est31 closed this as completed Aug 8, 2021
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

3 participants