pixels icon indicating copy to clipboard operation
pixels copied to clipboard

Not able to create pixel buffer with winit 0.29.2

Open paulfrische opened this issue 1 year ago • 8 comments

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

paulfrische avatar Oct 27 '23 16:10 paulfrische

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

J-Cake avatar Oct 27 '23 20:10 J-Cake

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 avatar Oct 28 '23 01:10 parasyte

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?

nxsaken avatar Oct 28 '23 22:10 nxsaken

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.

parasyte avatar Oct 28 '23 22:10 parasyte

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.

mkrasnitski avatar Jan 27 '24 03:01 mkrasnitski

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.

parasyte avatar Jan 27 '24 04:01 parasyte

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.

mkrasnitski avatar Jan 29 '24 06:01 mkrasnitski

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

oddman621 avatar Feb 21 '24 12:02 oddman621