dioxus icon indicating copy to clipboard operation
dioxus copied to clipboard

Opening Multiple Windows on Desktop-Windows Fails 9 out of 10 Times.

Open NotGovernor opened this issue 1 year ago • 1 comments

Problem

Opening Multiple Windows on Desktop-Windows Fails 9 out of 10 Times.

Steps To Reproduce

Steps to reproduce the behavior:

Create a single window with a single button that attempts to open a new window. New window command copy pasted from new window example code in the repo.

main.rs (excerpts)

#[derive(Clone, Routable, Debug, PartialEq)]
enum Route {
	#[route("/")]
	Home {},
}

fn main() {
	let cfg = dioxus::desktop::Config::new().with_menu(None);
	LaunchBuilder::desktop().with_cfg(cfg).launch(App);
}

#[component]
fn App() -> Element {
	rsx! {
		Router::<Route> {}
	}
}

#[component]
fn Home() -> Element {
	rsx! {
		div {	// Window background
			class: "bg-slate-900 flex w-screen h-screen text-white justify-center items-center",

			div {
				class: "{ButtonStyling}",
				// onclick: OpenAWindow,
				onclick: move |_| {
					let dom = VirtualDom::new(windows::userinfowindow::UserInfoWindow);
					dioxus::desktop::window().new_window(dom, Default::default());
				},
				"User Info"
			}
		}
	}
}

UserInfoWindow

#[component]
pub fn UserInfoWindow() -> Element {
	rsx! {
		"test"
	}
}

Start app with dx serve --hot-reload --platform desktop

Window with button loads fine.

1 out of every 10 times I start the app and click the button the new window opens fine.

9 out of 10 times I start the app and click the button I get:

Connected to hot reloading 🚀
thread 'main' panicked at C:\Users\User Name\.cargo\registry\src\index.crates.io-6f17d22bba15001f\dioxus-desktop-0.5.1\src\webview.rs:192:39:
called `Result::unwrap()` on an `Err` value: WebView2Error(WindowsError(Error { code: HRESULT(0x8007139F), message: "The group or resource is not in the correct state to perform the requested operation." }))

Here's the full backtrace: https://pastebin.com/h07yntzs

Expected behavior

The new window always opens.

Environment: dioxus = { version = "0.5", features = ["desktop", "router"] } rustc 1.78.0 OS: Windows Platform: Desktop

Thanks for everyone's work on this project!

NotGovernor avatar Jun 06 '24 18:06 NotGovernor

Decided to experiment a bit and had some odd behavior.

When running a combination of cargo run, dx serve and running the executable directly, sometimes I could run the app successfully and open as many windows as I wanted. Other times using the same method of execution, it would crash when creating the first window.

This, and based on the error message that the requested group/resource was not in a correct state, my guess is there is another process holding a handle to something the webview needs - I read it might be the webview itself when trying to share the EBWebView folder, but that's all I know for now.

I wonder if this occurred in previous Dioxus versions, perhaps it's an order-of-operations issue on Dioxus' part?

DogeDark avatar Jun 28 '24 06:06 DogeDark

Hi, I am facing the exact same issue when creating a Popup window, is there any progress on this topic?

Michaelschnabel-DM avatar Jul 24 '24 08:07 Michaelschnabel-DM

@Michaelschnabel-DM I checked this issue out again and I can't reproduce it on the git version of Dioxus. What version were you using?

DogeDark avatar Jul 26 '24 21:07 DogeDark

Note that we bumped wry and wry might've had the underlying issue. https://github.com/tauri-apps/wry/pull/1221

I'm going to close this since #2618 bumped wry which should bring along the fix - but please feel free to re-open if it the issue still persists with git version of dioxus.

We're going to release a pre-release of 0.6 very soon so you should have a stable-ish published checkpoint rather than relying on main.

jkelleyrtp avatar Jul 26 '24 22:07 jkelleyrtp