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

Not able to create pixel buffer with winit 0.29.2 #379

Closed
paulfrische opened this issue Oct 27, 2023 · 9 comments
Closed

Not able to create pixel buffer with winit 0.29.2 #379

paulfrische opened this issue Oct 27, 2023 · 9 comments
Labels
good first issue Good for newcomers help wanted Extra attention is needed

Comments

@paulfrische
Copy link

Hello there!
I've tried to create a pixel buffer with the following code but it ain't working with winit 0.29:

use pixels::{SurfaceTexture, Pixels};
use winit::{
    dpi::PhysicalSize,
    event_loop::EventLoop,
    window::WindowBuilder,
};

const WIDTH: u32 = 64;
const HEIGHT: u32 = 64;

fn main() {
    let event_loop = EventLoop::new().unwrap();

    let window = {
        WindowBuilder::new()
            .with_title("test test window")
            .with_inner_size(PhysicalSize::new(1000, 1000))
            .with_inner_size(PhysicalSize::new(1000, 1000))
            .with_resizable(false)
            .build(&event_loop)
            .unwrap()
    };

    let mut pixels =  {
        let window_size = window.inner_size();
        let surface_texture = SurfaceTexture::new(window_size.width, window_size.height, &window);
        Pixels::new(WIDTH, HEIGHT, surface_texture).unwrap()
    };
}

Compiler Error:

 error[E0277]: the trait bound `Window: pixels::raw_window_handle::HasRawWindowHandle` is not satisfied
   --> src/main.rs:26:90
    |
26  |         let surface_texture = SurfaceTexture::new(window_size.width, window_size.height, &window);
    |                               -------------------                                        ^^^^^^^ the trait `pixels::raw_window_handle::HasRawWind
owHandle` is not implemented for `Window`
    |                               |
    |                               required by a bound introduced by this call
    |
    = help: the following other types implement trait `pixels::raw_window_handle::HasRawWindowHandle`:
              pixels::raw_window_handle::WindowHandle<'_>
              &'a T

The same code works with winit 0.28

@J-Cake
Copy link

J-Cake commented Oct 27, 2023

I watched Winit tick over to 0.29.2 a few hours ago 😆. Am having this issue too

@parasyte
Copy link
Owner

parasyte commented Oct 28, 2023

winit 0.29 updated raw-window-handle (again). But they reference three versions of it: https://github.com/rust-windowing/winit/blob/v0.29.2/Cargo.toml#L61-L63 via feature flags rwh_06, rwh_05, and rwh_04.

While we are still on raw-window-handle 0.5, you should be able to use winit 0.29 by changing its feature flags:

winit = { version = "0.29", default-features = false, features = ["rwh_05", "x11", "wayland", "wayland-dlopen", "wayland-csd-adwaita"] }

I have not personally tested this, but it should be a usable workaround for the time being.

We will be on rwh 0.5 for as long as wgpu is. And they just released 0.18 two days ago with rwh 0.5.

@parasyte parasyte added help wanted Extra attention is needed good first issue Good for newcomers labels Oct 28, 2023
@nxsaken
Copy link
Contributor

nxsaken commented Oct 28, 2023

winit <0.28.7 is also broken on macOS Sonoma (see rust-windowing/winit#2876), the examples crash.

@parasyte am I understanding correctly that we should just update all winit dependencies in pixels and its examples to 0.29 with the compatibility feature flags to close this issue?

@parasyte
Copy link
Owner

I'm not terribly concerned about the examples. The main crate is agnostic to whether winit is used for platform integration or something else. The only hard dependency is on raw-window-handle = "0.5". Any projects using pixels can choose any version of winit, given that it is also compatible with our raw-window-handle dependency.

But in short, yes, I think that fixing the examples are the only thing we can do for this issue.

@mkrasnitski
Copy link
Contributor

Chiming in to say that wgpu 0.19 released last week and bumped their version of raw-window-handle to 0.6. It should therefore be possible for pixels to bump its wgpu dependency and enable using winit 0.29 with default features.

@parasyte
Copy link
Owner

Sounds good. There's an incomplete update to 0.18 in #386. I don't mind skipping a version, just pointing out that anyone who wants to do this work might find this PR a helpful starting point.

@mkrasnitski
Copy link
Contributor

mkrasnitski commented Jan 29, 2024

Update: I've been trying to upgrade winit and wgpu and have run into a few problems with CI:

  1. game-loop currently only supports winit 0.28. There's an open PR: fix(deps)!: update winit to 0.29 tuzz/game-loop#21
  2. imgui hasn't seen a release since april, but does support winit 0.29 if you use it as a git dependency.
  3. imgui-wgpu-rs only supports wgpu 0.17 and winit 0.27 (and upgrading them requires taking imgui as a git dependency).
  4. egui recently added support for wgpu 0.19, but they just had a recent release so a git dependency is needed for now.
  5. fltk doesn't support raw-window-handle 0.6.
  6. tao only added support for raw-window-handle 0.6 in version 0.24.

@oddman621
Copy link

This works for me. Try this:
winit = { version = "0.29", features = ["rwh_05"] }

@parasyte
Copy link
Owner

#391 should have closed this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

6 participants