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

Canvas ID not unique on a web page #2259

Closed
MarcAntoine-Arnaud opened this issue Apr 20, 2022 · 3 comments
Closed

Canvas ID not unique on a web page #2259

MarcAntoine-Arnaud opened this issue Apr 20, 2022 · 3 comments
Labels

Comments

@MarcAntoine-Arnaud
Copy link

Generating web component that requires winit to create a canvas, we found an issue as winit generates the Id of the canvas based on an auto-incremental number.
So our 2 canvas has the same data-raw-handle equals to 1, and using wgpu the fetch of the WindowID is the wrong one.

Do you have any suggestion to change the line here:

pub fn generate_id(&self) -> u32 {
and generate an UUID instead of an strictly increasing ID ?

Thanks,
Marc-Antoine

@madsmtm
Copy link
Member

madsmtm commented Apr 20, 2022

It would have to be done together with raw_window_handle::WebHandle.id.

Alternative solutions:

  • Generate a random id that is 32 bits wide (is that enough entropy?)
  • Put the auto-incremental number on document / as some global JS variable instead, so that different winit "instances" could talk together and avoid using the same one?
  • Add extension API WindowBuilderExtWebSys::with_raw_handle_id or similar for specifying this id, in your application pass global ID down using std::env::args()?

@parasyte
Copy link

parasyte commented Oct 1, 2022

A related issue is that raw-window-handle expects the canvas to be queried through the DOM using this id, which isn't always the case. For instance, when the window is created with an offscreen canvas, or when the canvas is within a Shadow DOM. The latter happened to one of my users in parasyte/pixels#309

I'm not entirely familiar with web-sys and wasm-bindgen, but HtmlCanvasElement implements From<JsValue>. Why isn't that used by WebWindowHandle? The only downside I can think of is that it adds a dependency on web-sys for everything that wants to use raw-window-handle in a web context (e.g. winit and wgpu). On the other hand, it also means that neither crate has to perform a carefully crafted (and obviously error-prone) dance with the DOM.

edit: I see most of the discussion around the current design was in this thread: rust-windowing/raw-window-handle#26 (comment)

@daxpedda
Copy link
Member

daxpedda commented Jun 5, 2023

I don't think this is really actionable by Winit, outside of assigning random UUIDs ... which I think is unnecessary for most use-cases and the issue described above can be dealt with WindowBuilder::with_canvas().

My stance on this is that this is a larger issue with raw-window-handle in that it doesn't take JsValue but instead relies on the data-raw-handle attribute, which isn't ideal.

Please reopen if WindowBuilder::with_canvas() isn't enough to fix this issue.

@daxpedda daxpedda closed this as not planned Won't fix, can't repro, duplicate, stale Jun 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

5 participants