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

Crash when trying to get any monitor #1893

Closed
RealDrPuc opened this issue May 23, 2021 · 4 comments
Closed

Crash when trying to get any monitor #1893

RealDrPuc opened this issue May 23, 2021 · 4 comments

Comments

@RealDrPuc
Copy link
Contributor

RealDrPuc commented May 23, 2021

Describe the bug
The execution of the program stops when I try to use primary_monitor(), available_monitors() or current_monitor().

To Reproduce
Steps to reproduce the behavior:

  1. Add the following code to the Builder::default()
.setup(|app| {
    let window = app.get_window("main").unwrap();
    println!("This will print!");
    let _monitors = window.available_monitors();
    println!("This won't.");

    Ok(())
})
  1. Run with yarn tauri dev.
  2. See console and the program's window.
  3. See that "This won't." isn't printed and the window does not respond.

Expected behavior
Can get monitors and, at least, not crash the program.

Screenshots
Images on here (imgur link).

Platform and Versions:
OS: Windows, version 10.0.19041 X64
Node: 16.2.0
NPM: 7.13.0
Yarn: 1.22.10
Rustc: 1.52.1
Webview2: 90.0.818.66
@tauri-apps/cli: 1.0.0-beta.1
@tauri-apps/api: Not installed

Additional context

Important!
This is the output of Tao's monitor_list example:

[src\main.rs:9] window.available_monitors().collect::<Vec<_>>() = [
    MonitorHandle {
        inner: MonitorHandle(
            0x0000000000010001,
        ),
    },
]
[src\main.rs:10] window.primary_monitor() = Some(
    MonitorHandle {
        inner: MonitorHandle(
            0x0000000000010001,
        ),
    },
)

Also, this issue applies on 2 separate Windows machines.

Stack Trace
I don't know how to get a stack trace, but I will happy to provide one if the issue needs it.

@Flakebi
Copy link
Contributor

Flakebi commented May 23, 2021

I get the same hang on Linux/Wayland with tauri 1.0.0-beta.1.

Edit: I guess this is a deadlock because tauri tries to schedule something and wait for it while we are currently in the scheduler thread. Starting a new thread and calling current_monitor() there creates thread 'main' panicked at 'not yet implemented'.

@RealDrPuc
Copy link
Contributor Author

I can confirm this is a Tauri issue, WRY and Tao can get the monitors but Tauri can't.

The following code returns Some(MonitorHandle { inner: MonitorHandle(0x10001) })

fn main() {
  use wry::{
    application::{
      event_loop::EventLoop,
      window::WindowBuilder,
    }
  };

  let event_loop = EventLoop::new();
  let window = WindowBuilder::new()
    .with_title("Monitor Test")
    .build(&event_loop).unwrap();

  let monitor = window.current_monitor();
  println!("{:?}", monitor);
}

@lucasfernog
Copy link
Member

On Linux the API is not implemented yet. I'll investigate the issue on Windows.

@lucasfernog
Copy link
Member

The problem here is that setup runs before the tao event loop is initialized, and the available_monitors (and most of the other window APIs) sends a message to the event loop and waits for the response, so it's a deadlock. There's not much to do here except document this behavior on the setup callback.

Example code that works:

.setup(|app| {
      let window = app.get_window("main").unwrap();
      std::thread::spawn(move || {
        println!("This will print!");
        let _monitors = window.available_monitors();
        println!("This will print!");
      });

      Ok(())
})

lucasfernog added a commit that referenced this issue Jun 16, 2021
* fix(core): deadlock on window getters, fixes #1893

* fix compilation without menu feature
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