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

Assert with connect_graphics_context from rectangle_simple_buffer #49

Open
yowl opened this issue Sep 14, 2024 · 5 comments
Open

Assert with connect_graphics_context from rectangle_simple_buffer #49

yowl opened this issue Sep 14, 2024 · 5 comments

Comments

@yowl
Copy link

yowl commented Sep 14, 2024

I'm trying to do a frame buffer example copying from the rectangle example in the repo but it seems that the bundled example asserts. Is it known to be working?

C:\github\wasi-gfx-runtime>cargo xtask run-demo --name rectangle_simple_buffer
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.04s
     Running `xtask\target\debug\xtask.exe run-demo --name rectangle_simple_buffer`
   Compiling rectangle_simple_buffer v0.1.0 (C:\github\wasi-gfx-runtime\examples\apps\rectangle_frame_buffer)
    Finished `release` profile [optimized] target(s) in 3.91s
   Compiling runtime v0.1.0 (C:\github\wasi-gfx-runtime\examples\runtime)
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 15.70s
     Running `target\debug\runtime.exe --example rectangle_simple_buffer`
thread 'tokio-runtime-worker' panicked at crates\wasi-frame-buffer-wasmtime\src\lib.rs:90:82:
called `Result::unwrap()` on an `Err` value: Unavailable
stack backtrace:
   0:     0x7ff60322bafa - std::backtrace_rs::backtrace::dbghelp64::trace
                               at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library\std\src\..\..\backtrace\src\backtrace\dbghelp64.rs:99
   1:     0x7ff60322bafa - std::backtrace_rs::backtrace::trace_unsynchronized
                               at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library\std\src\..\..\backtrace\src\backtrace\mod.rs:66
   2:     0x7ff60322bafa - std::sys_common::backtrace::_print_fmt
                               at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library\std\src\sys_common\backtrace.rs:68
   3:     0x7ff60322bafa - std::sys_common::backtrace::_print::impl$0::fmt
                               at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library\std\src\sys_common\backtrace.rs:44
   4:     0x7ff60324686b - core::fmt::rt::Argument::fmt
                               at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library\core\src\fmt\rt.rs:142
   5:     0x7ff60324686b - core::fmt::write
                               at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library\core\src\fmt\mod.rs:1153
   6:     0x7ff603227601 - std::io::Write::write_fmt<std::sys::pal::windows::stdio::Stderr>
                               at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library\std\src\io\mod.rs:1843
   7:     0x7ff60322b8e6 - std::sys_common::backtrace::print
                               at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library\std\src\sys_common\backtrace.rs:34
   8:     0x7ff60322da8f - std::panicking::default_hook::closure$1
                               at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library\std\src\panicking.rs:272
   9:     0x7ff60322d727 - std::panicking::default_hook
                               at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library\std\src\panicking.rs:292
  10:     0x7ff60322dfcd - std::panicking::rust_panic_with_hook
                               at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library\std\src\panicking.rs:779
  11:     0x7ff60322de89 - std::panicking::begin_panic_handler::closure$0
                               at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library\std\src\panicking.rs:657
  12:     0x7ff60322c189 - std::sys_common::backtrace::__rust_end_short_backtrace<std::panicking::begin_panic_handler::closure_env$0,never$>
                               at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library\std\src\sys_common\backtrace.rs:171
  13:     0x7ff60322db46 - std::panicking::begin_panic_handler
                               at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library\std\src\panicking.rs:645
  14:     0x7ff6032bd357 - core::panicking::panic_fmt
                               at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library\core\src\panicking.rs:72
  15:     0x7ff6032bd953 - core::result::unwrap_failed
                               at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library\core\src\result.rs:1654
  16:     0x7ff601dd207e - enum2$<core::result::Result<raw_window_handle::borrowed::WindowHandle,raw_window_handle::HandleError> >::unwrap
                               at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6\library\core\src\result.rs:1077
  17:     0x7ff601dd207e - wasi_frame_buffer_wasmtime::impl$5::display_api_ready
                               at C:\github\wasi-gfx-runtime\crates\wasi-frame-buffer-wasmtime\src\lib.rs:90
  18:     0x7ff601dd1b39 - wasi_frame_buffer_wasmtime::impl$4::display_api_ready
                               at C:\github\wasi-gfx-runtime\crates\wasi-frame-buffer-wasmtime\src\lib.rs:54
  19:     0x7ff601ddafd4 - wasi_graphics_context_wasmtime::GraphicsContext::connect_draw_api
                               at C:\github\wasi-gfx-runtime\crates\wasi-graphics-context-wasmtime\src\lib.rs:51
  20:     0x7ff601dd2603 - wasi_frame_buffer_wasmtime::impl$10::connect_graphics_context
                               at C:\github\wasi-gfx-runtime\crates\wasi-frame-buffer-wasmtime\src\lib.rs:158
  21:     0x7ff60132ba1e - wasi_frame_buffer_wasmtime::wasi::webgpu::frame_buffer::impl$1::connect_graphics_context<dyn$<wasi_frame_buffer_wasmtime::WasiFrameBufferView> >
                               at C:\github\wasi-gfx-runtime\crates\wasi-frame-buffer-wasmtime\src\lib.rs:12
  22:     0x7ff60114937c - wasi_frame_buffer_wasmtime::wasi::webgpu::frame_buffer::add_to_linker_get_host::closure$3<runtime::HostState,wasi_frame_buffer_wasmtime::add_to_linker::closure_env$0<runtime::HostState> >
                               at C:\github\wasi-gfx-runtime\crates\wasi-frame-buffer-wasmtime\src\lib.rs:12
  23:     0x7ff600fb8d71 - wasmtime::runtime::component::func::host::impl$0::entrypoint::closure$0::closure$0<runtime::HostState,wasi_frame_buffer_wasmtime::wasi::webgpu::frame_buffer::add_to_linker_get_host::closure_env$3<runtime::HostState,wasi_frame_buffer_wasmtime::add_to_linke
                               at C:\Users\scott\.cargo\registry\src\index.crates.io-6f17d22bba15001f\wasmtime-21.0.1\src\runtime\component\func\host.rs:68
  24:     0x7ff600ff9a06 - wasmtime::runtime::component::func::host::call_host<runtime::HostState,tuple$<wasmtime::runtime::component::resources::Resource<wasi_frame_buffer_wasmtime::FBSurfaceArc>,wasmtime::runtime::component::resources::Resource<wasi_graphics_context_wasmtime::Gra
                               at C:\Users\scott\.cargo\registry\src\index.crates.io-6f17d22bba15001f\wasmtime-21.0.1\src\runtime\component\func\host.rs:216
  25:     0x7ff600fb5144 - wasmtime::runtime::component::func::host::impl$0::entrypoint::closure$0<runtime::HostState,wasi_frame_buffer_wasmtime::wasi::webgpu::frame_buffer::add_to_linker_get_host::closure_env$3<runtime::HostState,wasi_frame_buffer_wasmtime::add_to_linker::closure_
                               at C:\Users\scott\.cargo\registry\src\index.crates.io-6f17d22bba15001f\wasmtime-21.0.1\src\runtime\component\func\host.rs:60
  26:     0x7ff601403641 - core::panic::unwind_safe::impl$25::call_once<enum2$<core::result::Result<tuple$<>,anyhow::Error> >,wasmtime::runtime::component::func::host::impl$0::entrypoint::closure_env$0<runtime::HostState,wasi_frame_buffer_wasmtime::wasi::webgpu::frame_buffer::add_t
                               at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6\library\core\src\panic\unwind_safe.rs:272
  27:     0x7ff60149e429 - std::panicking::try::do_call<core::panic::unwind_safe::AssertUnwindSafe<wasmtime::runtime::component::func::host::impl$0::entrypoint::closure_env$0<runtime::HostState,wasi_frame_buffer_wasmtime::wasi::webgpu::frame_buffer::add_to_linker_get_host::closure_
                               at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6\library\std\src\panicking.rs:552
  28:     0x7ff6014b4333 - std::panicking::try::do_catch<core::panic::unwind_safe::AssertUnwindSafe<wasmtime::runtime::component::func::host::impl$0::entrypoint::closure_env$0<runtime::HostState,wasi_webgpu_wasmtime::wasi::webgpu::webgpu::add_to_linker_get_host::closure_env$203<run
  29:     0x7ff60148e3bb - std::panicking::try<enum2$<core::result::Result<tuple$<>,anyhow::Error> >,core::panic::unwind_safe::AssertUnwindSafe<wasmtime::runtime::component::func::host::impl$0::entrypoint::closure_env$0<runtime::HostState,wasi_frame_buffer_wasmtime::wasi::webgpu::f
                               at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6\library\std\src\panicking.rs:516
  30:     0x7ff6013271c1 - std::panic::catch_unwind<core::panic::unwind_safe::AssertUnwindSafe<wasmtime::runtime::component::func::host::impl$0::entrypoint::closure_env$0<runtime::HostState,wasi_frame_buffer_wasmtime::wasi::webgpu::frame_buffer::add_to_linker_get_host::closure_env$
                               at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6\library\std\src\panic.rs:146
  31:     0x7ff6014c4dd9 - wasmtime::runtime::vm::traphandlers::catch_unwind_and_longjmp<enum2$<core::result::Result<tuple$<>,anyhow::Error> >,wasmtime::runtime::component::func::host::impl$0::entrypoint::closure_env$0<runtime::HostState,wasi_frame_buffer_wasmtime::wasi::webgpu::fr
                               at C:\Users\scott\.cargo\registry\src\index.crates.io-6f17d22bba15001f\wasmtime-21.0.1\src\runtime\vm\traphandlers.rs:123
  32:     0x7ff600f6cc69 - wasmtime::runtime::component::func::host::handle_result<wasmtime::runtime::component::func::host::impl$0::entrypoint::closure_env$0<runtime::HostState,wasi_frame_buffer_wasmtime::wasi::webgpu::frame_buffer::add_to_linker_get_host::closure_env$3<runtime::H
                               at C:\Users\scott\.cargo\registry\src\index.crates.io-6f17d22bba15001f\wasmtime-21.0.1\src\runtime\component\func\host.rs:294
  33:     0x7ff600f97503 - wasmtime::runtime::component::func::host::HostFunc::entrypoint<runtime::HostState,wasi_frame_buffer_wasmtime::wasi::webgpu::frame_buffer::add_to_linker_get_host::closure_env$3<runtime::HostState,wasi_frame_buffer_wasmtime::add_to_linker::closure_env$0<run
                               at C:\Users\scott\.cargo\registry\src\index.crates.io-6f17d22bba15001f\wasmtime-21.0.1\src\runtime\component\func\host.rs:59
  34:      0x247c420cb21 - <unknown>
  35:      0x247c41f14bc - <unknown>
  36:      0x247c4205c11 - <unknown>
@yowl
Copy link
Author

yowl commented Sep 14, 2024

Looks like the window handle in not available yet, but what should I do to wait for that to be available, is there a pollable?

@yowl
Copy link
Author

yowl commented Sep 14, 2024

I did try waiting for a resize event, but there is still no window_handle , perhaps because I'm on windows...?

@yowl
Copy link
Author

yowl commented Sep 14, 2024

update after adding lots of println, WasiWinitEventLoopProxy, create_window, I'm no expert here, but the oneshot::channel / receiver seems to loose the window_handle in the receiver.await. In user_event the handle exists on the MiniCanvas just before response_channel.send but on the receiver side it is Err(Unavailable). Just noting my observations in case this rings any bells, but will contiue to dig a bit more, although oneshot is not part of this repo.

@yowl
Copy link
Author

yowl commented Sep 14, 2024

Window on WIndows has some thread affinity restrictions, https://docs.rs/winit/latest/winit/platform/windows/trait.WindowExtWindows.html#tymethod.window_handle_any_thread

Seems like my problem, exactly what we can't do on a different thread is not yet clear, but the handle by default is Unavailable unless window_handle_any_thread is used.

@yowl
Copy link
Author

yowl commented Sep 15, 2024

I think softbuffer may be the next problem, I wonder if WasiWinitEventLoop could have an option to be single threaded?

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

1 participant