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

[bug] Panic on Windows if a native window is created #3883

Closed
dceddia opened this issue Apr 11, 2022 · 6 comments
Closed

[bug] Panic on Windows if a native window is created #3883

dceddia opened this issue Apr 11, 2022 · 6 comments
Assignees

Comments

@dceddia
Copy link
Contributor

dceddia commented Apr 11, 2022

Describe the bug

When a native window is created with AppHandle::create_tao_window, then doing anything to the app causes it to panic. I think anything that causes a window event causes a panic.

With tauri-1.0.0-rc.4 and tao 0.6.4 this was working fine, but after updating to tauri-1.0.0-rc.6 and tao 0.7.0 it's started panicing.

Reproduction

This repo has a minimal reproduction: https://github.com/dceddia/tauri-window-hang-repro

See the stack trace below. I think the relevant part is #5 - tauri-runtime-wry-0.3.5\src\lib.rs:2447, here. That section looks like it's handling window events, and it seems to make the assumption that an event will definitely come from a window with a webview.

The webview_id_map, too, assumes that a call to get() will find an associated window, and unwraps the Option, which causes the panic.

Event::WindowEvent {
    event, window_id, ..
} => {
    let window_id = webview_id_map.get(&window_id);
    ...

Expected behavior

No panic :)

Platform and versions

$ yarn tauri info
yarn run v1.22.17
$ tauri info

Environment
  › OS: Windows 10.0.19044 X64
  › Webview2: 100.0.1185.36
  › MSVC:
      - Visual Studio Build Tools 2019
      - Visual Studio Community 2019
  › Node.js: 16.9.0
  › npm: 7.22.0
  › pnpm: Not installed!
  › yarn: 1.22.17
  › rustup: 1.24.3
  › rustc: 1.58.1
  › cargo: 1.58.0
  › Rust toolchain: stable-x86_64-pc-windows-msvc

Packages
  › @tauri-apps/cli [NPM]: 1.0.0-rc.7
  › @tauri-apps/api [NPM]: 1.0.0-rc.3
  › tauri [RUST]: 1.0.0-rc.6,
  › tauri-build [RUST]: 1.0.0-rc.5,
  › tao [RUST]: 0.7.0,
  › wry [RUST]: 0.14.0,

App
  › build-type: bundle
  › CSP: unset
  › distDir: ../public
  › devPath: http://localhost:8080/
  › framework: Svelte
  › bundler: Rollup

App directory structure
  ├─ .git
  ├─ .vscode
  ├─ node_modules
  ├─ public
  ├─ src
  └─ src-tauri

Stack trace

thread 'main' panicked at 'called `Option::unwrap()` on a `None` value', C:\Users\Dave\.cargo\registry\src\github.com-1ecc6299db9ec823\tauri-runtime-wry-0.3.5\src\lib.rs:128:36
stack backtrace:
   0: std::panicking::begin_panic_handler
             at /rustc/db9d1b20bba1968c1ec1fc49616d4742c1725b4b\/library\std\src\panicking.rs:498
   1: core::panicking::panic_fmt
             at /rustc/db9d1b20bba1968c1ec1fc49616d4742c1725b4b\/library\core\src\panicking.rs:107
   2: core::panicking::panic
             at /rustc/db9d1b20bba1968c1ec1fc49616d4742c1725b4b\/library\core\src\panicking.rs:48
   3: enum$<core::option::Option<ref$<u64> >, 1, 18446744073709551615, Some>::unwrap<ref$<u64> >
             at /rustc/db9d1b20bba1968c1ec1fc49616d4742c1725b4b\library\core\src\option.rs:746
   4: tauri_runtime_wry::WebviewIdStore::get
             at C:\Users\Dave\.cargo\registry\src\github.com-1ecc6299db9ec823\tauri-runtime-wry-0.3.5\src\lib.rs:128
   5: tauri_runtime_wry::handle_event_loop<enum$<tauri::EventLoopMessage> >
             at C:\Users\Dave\.cargo\registry\src\github.com-1ecc6299db9ec823\tauri-runtime-wry-0.3.5\src\lib.rs:2447
   6: tauri_runtime_wry::impl$49::run::closure$0<enum$<tauri::EventLoopMessage>,tauri::app::impl$17::run::closure$0>
             at C:\Users\Dave\.cargo\registry\src\github.com-1ecc6299db9ec823\tauri-runtime-wry-0.3.5\src\lib.rs:1954
   7: tao::platform_impl::platform::event_loop::impl$2::run_return::closure$0<enum$<tauri_runtime_wry::Message<enum$<tauri::EventLoopMessage> > >,tauri_runtime_wry::impl$49::run::closure$0>
             at C:\Users\Dave\.cargo\registry\src\github.com-1ecc6299db9ec823\tao-0.7.0\src\platform_impl\windows\event_loop.rs:225
   8: alloc::boxed::impl$45::call_mut<tuple$<enum$<tao::event::Event<enum$<tauri_runtime_wry::Message<enum$<tauri::EventLoopMessage> > > > >,ref_mut$<enum$<tao::event_loop::ControlFlow> > >,dyn$<core::ops::function::FnMut<tuple$<enum$<tao::event::Event<enum$<ta
             at /rustc/db9d1b20bba1968c1ec1fc49616d4742c1725b4b\library\alloc\src\boxed.rs:1701
   9: tao::platform_impl::platform::event_loop::runner::impl$3::call_event_handler::closure$0<enum$<tauri_runtime_wry::Message<enum$<tauri::EventLoopMessage> > > >
             at C:\Users\Dave\.cargo\registry\src\github.com-1ecc6299db9ec823\tao-0.7.0\src\platform_impl\windows\event_loop\runner.rs:249
  10: core::panic::unwind_safe::impl$23::call_once<tuple$<>,tao::platform_impl::platform::event_loop::runner::impl$3::call_event_handler::closure$0>
             at /rustc/db9d1b20bba1968c1ec1fc49616d4742c1725b4b\library\core\src\panic\unwind_safe.rs:271
  11: std::panicking::try::do_call<core::panic::unwind_safe::AssertUnwindSafe<tao::platform_impl::platform::event_loop::runner::impl$3::call_event_handler::closure$0>,tuple$<> >
             at /rustc/db9d1b20bba1968c1ec1fc49616d4742c1725b4b\library\std\src\panicking.rs:406
  12: core::option::impl$41::from_residual<tuple$<alloc::string::String,alloc::string::String> >
  13: std::panicking::try<tuple$<>,core::panic::unwind_safe::AssertUnwindSafe<tao::platform_impl::platform::event_loop::runner::impl$3::call_event_handler::closure$0> >
             at /rustc/db9d1b20bba1968c1ec1fc49616d4742c1725b4b\library\std\src\panicking.rs:370
  14: std::panic::catch_unwind<core::panic::unwind_safe::AssertUnwindSafe<tao::platform_impl::platform::event_loop::runner::impl$3::call_event_handler::closure$0>,tuple$<> >
             at /rustc/db9d1b20bba1968c1ec1fc49616d4742c1725b4b\library\std\src\panic.rs:133
  15: tao::platform_impl::platform::event_loop::runner::EventLoopRunner<enum$<tauri_runtime_wry::Message<enum$<tauri::EventLoopMessage> > > >::catch_unwind<enum$<tauri_runtime_wry::Message<enum$<tauri::EventLoopMessage> > >,tuple$<>,tao::platform_impl::platform
             at C:\Users\Dave\.cargo\registry\src\github.com-1ecc6299db9ec823\tao-0.7.0\src\platform_impl\windows\event_loop\runner.rs:155
  16: tao::platform_impl::platform::event_loop::runner::EventLoopRunner<enum$<tauri_runtime_wry::Message<enum$<tauri::EventLoopMessage> > > >::call_event_handler<enum$<tauri_runtime_wry::Message<enum$<tauri::EventLoopMessage> > > >
             at C:\Users\Dave\.cargo\registry\src\github.com-1ecc6299db9ec823\tao-0.7.0\src\platform_impl\windows\event_loop\runner.rs:241
  17: tao::platform_impl::platform::event_loop::runner::EventLoopRunner<enum$<tauri_runtime_wry::Message<enum$<tauri::EventLoopMessage> > > >::send_event<enum$<tauri_runtime_wry::Message<enum$<tauri::EventLoopMessage> > > >
             at C:\Users\Dave\.cargo\registry\src\github.com-1ecc6299db9ec823\tao-0.7.0\src\platform_impl\windows\event_loop\runner.rs:223
  18: tao::platform_impl::platform::event_loop::SubclassInput<enum$<tauri_runtime_wry::Message<enum$<tauri::EventLoopMessage> > > >::send_event<enum$<tauri_runtime_wry::Message<enum$<tauri::EventLoopMessage> > > >
             at C:\Users\Dave\.cargo\registry\src\github.com-1ecc6299db9ec823\tao-0.7.0\src\platform_impl\windows\event_loop.rs:107
  19: tao::platform_impl::platform::event_loop::public_window_callback_inner::closure$6<enum$<tauri_runtime_wry::Message<enum$<tauri::EventLoopMessage> > > >
             at C:\Users\Dave\.cargo\registry\src\github.com-1ecc6299db9ec823\tao-0.7.0\src\platform_impl\windows\event_loop.rs:1632
  20: core::ops::function::FnOnce::call_once<tao::platform_impl::platform::event_loop::public_window_callback_inner::closure$6,tuple$<> >
             at /rustc/db9d1b20bba1968c1ec1fc49616d4742c1725b4b\library\core\src\ops\function.rs:227
  21: core::panic::unwind_safe::impl$23::call_once<tuple$<>,tao::platform_impl::platform::event_loop::public_window_callback_inner::closure$6>
             at /rustc/db9d1b20bba1968c1ec1fc49616d4742c1725b4b\library\core\src\panic\unwind_safe.rs:271
  22: std::panicking::try::do_call<core::panic::unwind_safe::AssertUnwindSafe<tao::platform_impl::platform::event_loop::public_window_callback_inner::closure$6>,tuple$<> >
             at /rustc/db9d1b20bba1968c1ec1fc49616d4742c1725b4b\library\std\src\panicking.rs:406
  23: core::option::impl$41::from_residual<tuple$<alloc::string::String,alloc::string::String> >
  24: std::panicking::try<tuple$<>,core::panic::unwind_safe::AssertUnwindSafe<tao::platform_impl::platform::event_loop::public_window_callback_inner::closure$6> >
             at /rustc/db9d1b20bba1968c1ec1fc49616d4742c1725b4b\library\std\src\panicking.rs:370
  25: std::panic::catch_unwind<core::panic::unwind_safe::AssertUnwindSafe<tao::platform_impl::platform::event_loop::public_window_callback_inner::closure$6>,tuple$<> >
             at /rustc/db9d1b20bba1968c1ec1fc49616d4742c1725b4b\library\std\src\panic.rs:133
  26: tao::platform_impl::platform::event_loop::runner::EventLoopRunner<enum$<tauri_runtime_wry::Message<enum$<tauri::EventLoopMessage> > > >::catch_unwind<enum$<tauri_runtime_wry::Message<enum$<tauri::EventLoopMessage> > >,tuple$<>,tao::platform_impl::platform
             at C:\Users\Dave\.cargo\registry\src\github.com-1ecc6299db9ec823\tao-0.7.0\src\platform_impl\windows\event_loop\runner.rs:155
  27: tao::platform_impl::platform::event_loop::public_window_callback_inner<enum$<tauri_runtime_wry::Message<enum$<tauri::EventLoopMessage> > > >
             at C:\Users\Dave\.cargo\registry\src\github.com-1ecc6299db9ec823\tao-0.7.0\src\platform_impl\windows\event_loop.rs:1978
  28: tao::platform_impl::platform::event_loop::public_window_callback<enum$<tauri_runtime_wry::Message<enum$<tauri::EventLoopMessage> > > >
             at C:\Users\Dave\.cargo\registry\src\github.com-1ecc6299db9ec823\tao-0.7.0\src\platform_impl\windows\event_loop.rs:848
  29: DefSubclassProc
  30: DefSubclassProc
  31: CallWindowProcW
  32: DispatchMessageW
  33: SendMessageTimeoutW
  34: KiUserCallbackDispatcher
  35: NtUserGetMessage
  36: GetMessageW
  37: windows::Windows::Win32::UI::WindowsAndMessaging::GetMessageW<windows::Windows::Win32::Foundation::HWND>
             at C:\Users\Dave\.cargo\registry\src\github.com-1ecc6299db9ec823\windows-0.30.0\src\Windows\Win32\UI\WindowsAndMessaging\mod.rs:4336
  38: tao::platform_impl::platform::event_loop::EventLoop<enum$<tauri_runtime_wry::Message<enum$<tauri::EventLoopMessage> > > >::run_return<enum$<tauri_runtime_wry::Message<enum$<tauri::EventLoopMessage> > >,tauri_runtime_wry::impl$49::run::closure$0>
             at C:\Users\Dave\.cargo\registry\src\github.com-1ecc6299db9ec823\tao-0.7.0\src\platform_impl\windows\event_loop.rs:236
  39: tao::platform_impl::platform::event_loop::EventLoop<enum$<tauri_runtime_wry::Message<enum$<tauri::EventLoopMessage> > > >::run<enum$<tauri_runtime_wry::Message<enum$<tauri::EventLoopMessage> > >,tauri_runtime_wry::impl$49::run::closure$0>
             at C:\Users\Dave\.cargo\registry\src\github.com-1ecc6299db9ec823\tao-0.7.0\src\platform_impl\windows\event_loop.rs:209
  40: tao::event_loop::EventLoop<enum$<tauri_runtime_wry::Message<enum$<tauri::EventLoopMessage> > > >::run<enum$<tauri_runtime_wry::Message<enum$<tauri::EventLoopMessage> > >,tauri_runtime_wry::impl$49::run::closure$0>
             at C:\Users\Dave\.cargo\registry\src\github.com-1ecc6299db9ec823\tao-0.7.0\src\event_loop.rs:177
  41: tauri_runtime_wry::impl$49::run<enum$<tauri::EventLoopMessage>,tauri::app::impl$17::run::closure$0>
             at C:\Users\Dave\.cargo\registry\src\github.com-1ecc6299db9ec823\tauri-runtime-wry-0.3.5\src\lib.rs:1953
  42: tauri::app::App<tauri_runtime_wry::Wry<enum$<tauri::EventLoopMessage> > >::run<tauri_runtime_wry::Wry<enum$<tauri::EventLoopMessage> >,app::main::closure$0>
             at C:\Users\Dave\.cargo\registry\src\github.com-1ecc6299db9ec823\tauri-1.0.0-rc.6\src\app.rs:614
  43: app::main
             at .\src\main.rs:15
  44: core::ops::function::FnOnce::call_once<void (*)(),tuple$<> >
             at /rustc/db9d1b20bba1968c1ec1fc49616d4742c1725b4b\library\core\src\ops\function.rs:227
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
[0410/215004.211:ERROR:window_impl.cc(114)] Failed to unregister class Chrome_WidgetWin_0. Error = 0

Additional context

I'm not sure if I'm creating this window at the right time, or if I should be depending on tao directly here or if there's a better way, so let me know if anything could be better.

The goal of having this native window is to make an empty overlay that I can draw in with wgpu.

@lucasfernog
Copy link
Member

Thanks for the report, fix will be published soon. Really interesting use case btw :)

@dceddia
Copy link
Contributor Author

dceddia commented Apr 21, 2022

Awesome, thanks Lucas!

@dceddia
Copy link
Contributor Author

dceddia commented May 13, 2022

@lucasfernog I finally got around to updating, and this panic is fixed, but now there's a deadlock 😅 It's around the same place, right here when it receives a WindowEvent:

    Event::WindowEvent {
      event, window_id, ..
    } => {
      let window_id = webview_id_map.get(&window_id); // <<< hangs here

The event it's hanging on is Moved, and I imagine that both the parent and my child window are getting the Moved event and then both try to lock the webview_id_map. Does this mean I'm creating the window on the wrong thread or something? Do I need to give it its own event loop?

I've put in a bunch of println's in my code to narrow it down and it seems like it's able to at least create the window and send + finish a couple resize events, so it's not immediately broken, but from a user standpoint it looks like the app hangs immediately on startup. My code that creates the window looks like

pub fn add_overlay(app_handle: &AppHandle) -> impl OverlayView {
    let window = app_handle
        .get_window("main")
        .expect("failed to get main window");

    let hwnd = window.hwnd().expect("failed to get HWND");
    let overlay = app_handle
        .create_tao_window(move || {
            let window_builder = tao::window::WindowBuilder::new()
                .with_always_on_top(false)
                .with_decorations(false)
                .with_resizable(false)
                .with_visible(false)
                .with_position(tao::dpi::LogicalPosition::<u32>::new(30, 30))
                .with_owner_window(hwnd) 
                .with_inner_size(tao::dpi::LogicalSize::<u32>::new(200, 200));

            ("WGPU Target".to_string(), window_builder)
        })
        .expect("failed to create overlay window");
...
}

I put this as a reply here since there's already some context, but I can create a separate issue if that makes more sense.

@FabianLars FabianLars reopened this May 13, 2022
@lucasfernog
Copy link
Member

@dceddia can you file a separate issue with an example I can use to reproduce it? tried with your tauri-window-hang-repro but couldn't reproduce it. Thanks!

@dceddia
Copy link
Contributor Author

dceddia commented May 13, 2022

Ah, sorry - should've tried that first! I just went to update the example and realized that the overlay didn't have much to do with it.

The problem was that I was making changes to the window in a tauri::command that wasn't async. Making the commands async fixed the issue. I had the same problem (hung window) when I tried to create a new window in a non-async command. I guess window operations need to happen in another thread!

@lucasfernog
Copy link
Member

Can you file an issue with your command? If it doesn't work in the main thread it's a bug.

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

No branches or pull requests

3 participants