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

Fix your tutorial #553

Closed
Zekinler opened this issue Jun 4, 2024 · 4 comments
Closed

Fix your tutorial #553

Zekinler opened this issue Jun 4, 2024 · 4 comments

Comments

@Zekinler
Copy link

Zekinler commented Jun 4, 2024

It was a good tutorial (the tutorial recommended by gfx-rs themselves) for wgpu.
Now it provides code that has compiler errors and says things referencing other things that dont exist.
If you're going to update your tutorial, why would you ever deploy incomplete, spotty pages to the main branch?

@DeveloperGY
Copy link

I dont think the tutorial has any errors from what ive seen. Check the versions of your dependencies to make sure they match with what the guide says since both wgpu and winit have had some updates since that last change to the guide.

If you are using the correct versions of the dependencies and have double checked that you followed the guide correctly, then posting what errors you've been getting would be helpful since it can help narrow down exactly what's causing it.

What I believe happened here is that you used the most recent versions of wgpu and winit which has some issues when it comes to creating the surface. The way to fix it is mentioned here. Essentially, you wrap the winit window in an Arc and then the Surface should contain a 'static lifetime.

If thats not the issue that you have, as mentioned before, please paste the errors you are getting to give a lead as to what is going wrong.

@phrozen
Copy link

phrozen commented Jun 5, 2024

I was able to make it work following this other issue #549 . Unfortunately, as I commented there, a LOT has to change to make it happen, and with winit = 0.30.0 the window is no longer created in the run function and the WASM version no longer works. I believe the first section definitely needs a rewrite to simplify and fix all the errors introduced by recent breaking changes.

@toolateralus
Copy link

toolateralus commented Jun 12, 2024

yeah Im having a very hard time getting run going because the tutorial has either deprecated or completely erroneous code in it. specifically creating the window and running it.
for example, in the first piece of code suggested:

// .. in 'fn run()'
env_logger::init();
    let event_loop = EventLoop::new().unwrap();
    let window = WindowBuilder::new().build(&event_loop).unwrap();

    event_loop.run(move |event, control_flow| match event {
        Event::WindowEvent {
            ref event,
            window_id,
        } if window_id == window.id() => match event {
            WindowEvent::CloseRequested
            | WindowEvent::KeyboardInput {
                event:
                    KeyEvent {
                        state: ElementState::Pressed,
                        physical_key: PhysicalKey::Code(KeyCode::Escape),
                        ..
                    },
                ..
            } => control_flow.exit(),
            _ => {}
        },
        _ => {}
    });

WindowBuilder no longer exists, (unless im missing a dependency? in that case, theres a missing listed dependency)
event_loop.run(...) is deprecated.

Then, in the later revised version of run

pub async fn run() {
    // Window setup...

    let mut state = State::new(&window).await;

    event_loop.run(move |event, control_flow| {
        match event {
            Event::WindowEvent {
                ref event,
                window_id,
            } if window_id == state.window().id() => match event {
                WindowEvent::CloseRequested
                | WindowEvent::KeyboardInput {
                    input:
                        KeyboardInput {
                            state: ElementState::Pressed,
                            virtual_keycode: Some(VirtualKeyCode::Escape),
                            ..
                        },
                    ..
                } => *control_flow = ControlFlow::Exit,
                _ => {}
            },
            _ => {}
        }
    });
}

The Window::KeyboardEvent does not have an input field, and KeyboardInput does not exist.
ControlFlow::Exit does not exist.

I may be completely wrong and may be missing dependencies, but it seems the tutorial just is impossible to follow without heavy modification. I have spent almost an hour finding workarounds for this, but winit has little to no documentation and its very challenging as a beginner to figure out how to fix this.

@sotrh
Copy link
Owner

sotrh commented Jun 12, 2024

There are breaking changes between winit = "0.29" and winit = "0.30". In the tutorial I specify that I'm using 0.29.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants