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

Unable to use appit with wry #5

Open
Wybxc opened this issue Dec 15, 2024 · 1 comment
Open

Unable to use appit with wry #5

Wybxc opened this issue Dec 15, 2024 · 1 comment

Comments

@Wybxc
Copy link

Wybxc commented Dec 15, 2024

main.rs:

use appit::{Message, Run, RunningWindow, WindowBehavior};
use wry::{WebView, WebViewBuilder};

pub struct MainWindow {
    pub webview: WebView,
}

impl<M: Message> WindowBehavior<M> for MainWindow {
    type Context = ();

    fn initialize(window: &mut RunningWindow<M>, _context: Self::Context) -> Self {
        let webview = WebViewBuilder::new()
            .with_url("https://tauri.app")
            .build(window.winit())
            .unwrap();
        Self { webview }
    }

    fn redraw(&mut self, _window: &mut RunningWindow<M>) {
        println!("Should redraw");
    }
}

fn main() {
    MainWindow::run().unwrap();
}

Cargo.toml:

[dependencies]
appit = "0.4.0"
winit = "0.30.5"
wry = "0.47.2"

Error message:

thread '<unnamed>' panicked at src/main.rs:15:14:
called `Result::unwrap()` on an `Err` value: WindowHandleError(Unavailable)
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
@ecton
Copy link
Member

ecton commented Dec 19, 2024

I'm not familiar with Wry, but my best guess is that it needs to be used from the main thread -- and that's pretty much the only difference between appit and a normal winit app. It may not be worth using appit with Wry, because of the extra work it might require to interact with it from a multi-threaded environment.

If you do want to try to make this work with appit, I would try doing what my project Kludgine does to ensure code is executed on the event loop. First, it uses PendingApp::new_with_event_callback to register a callback handling AppEvent<T> events. One of the types is CreateSurface, because wgpu requires that surface creation happens on the main thread. Then whenever a surface is needed, a request can be sent.

If this guess doesn't allow it to work, it might be worth asking the Wry project what is needed to ensure it can be used from other threads than the main thread.

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

2 participants