parasyte / pixels

A tiny hardware-accelerated pixel frame buffer. 🦀
https://docs.rs/pixels
MIT License
1.82k stars 123 forks source link

Not able to create pixel buffer with winit 0.29.2 #379

Closed paulfrische closed 2 months ago

paulfrische commented 1 year ago

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 commented 1 year ago

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

parasyte commented 1 year ago

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.

nxsaken commented 1 year ago

winit <0.28.7 is also broken on macOS Sonoma (see https://github.com/rust-windowing/winit/issues/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 commented 1 year ago

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 commented 10 months ago

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 commented 10 months ago

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 commented 10 months ago

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: https://github.com/tuzz/game-loop/pull/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 commented 9 months ago

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

parasyte commented 2 months ago

391 should have closed this.