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 wgpu integration example #1139

Merged
merged 1 commit into from
Sep 26, 2022
Merged

Conversation

thenlevy
Copy link
Contributor

@thenlevy thenlevy commented Dec 6, 2021

On master, I can make the integration example crash on XFCE by resizing the window quickly. I believe this to be due to the fact that the window's size can change between the last time we processed the Resize event, and the moment we generate the next frame texture.

This PR avoids this by checking that the last processed size is correct before redrawing.

@hecrj
Copy link
Member

hecrj commented Dec 9, 2021

What kind of crash? Do you get a backtrace?

I think we should probably make all of our drawing operations return a Result and fail gracefully.

@thenlevy
Copy link
Contributor Author

thenlevy commented Dec 9, 2021

It is a set_scissor_rect error probably due to a mismatch between the Viewport's and the frame's dimensions.
Here is a backtrace

[2021-12-09T13:21:42Z ERROR wgpu::backend::direct] Handling wgpu errors as fatal by default
thread 'main' panicked at 'wgpu error: Validation Error

Caused by:
    In a RenderPass
      note: encoder = `<CommandBuffer-(0, 51, Vulkan)>`
    In a set_scissor_rect command
    Invalid ScissorRect parameters

', /home/nlevy/.cargo/registry/src/gh.neting.cc-1ecc6299db9ec823/wgpu-0.11.1/src/backend/direct.rs:2195:5
stack backtrace:
   0: rust_begin_unwind
             at /rustc/59eed8a2aac0230a8b53e89d4e99d55912ba6b35/library/std/src/panicking.rs:517:5
   1: std::panicking::begin_panic_fmt
             at /rustc/59eed8a2aac0230a8b53e89d4e99d55912ba6b35/library/std/src/panicking.rs:460:5
   2: wgpu::backend::direct::default_error_handler
             at /home/nlevy/.cargo/registry/src/gh.neting.cc-1ecc6299db9ec823/wgpu-0.11.1/src/backend/direct.rs:2195:5
   3: core::ops::function::Fn::call
             at /rustc/59eed8a2aac0230a8b53e89d4e99d55912ba6b35/library/core/src/ops/function.rs:70:5
   4: <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call
             at /rustc/59eed8a2aac0230a8b53e89d4e99d55912ba6b35/library/alloc/src/boxed.rs:1650:9
   5: wgpu::backend::direct::ErrorSinkRaw::handle_error
             at /home/nlevy/.cargo/registry/src/gh.neting.cc-1ecc6299db9ec823/wgpu-0.11.1/src/backend/direct.rs:2183:9
   6: wgpu::backend::direct::Context::handle_error
             at /home/nlevy/.cargo/registry/src/gh.neting.cc-1ecc6299db9ec823/wgpu-0.11.1/src/backend/direct.rs:184:9
   7: <wgpu::backend::direct::Context as wgpu::Context>::command_encoder_end_render_pass
             at /home/nlevy/.cargo/registry/src/gh.neting.cc-1ecc6299db9ec823/wgpu-0.11.1/src/backend/direct.rs:1957:13
   8: <wgpu::RenderPass as core::ops::drop::Drop>::drop
             at /home/nlevy/.cargo/registry/src/gh.neting.cc-1ecc6299db9ec823/wgpu-0.11.1/src/lib.rs:2823:13
   9: core::ptr::drop_in_place<wgpu::RenderPass>
             at /rustc/59eed8a2aac0230a8b53e89d4e99d55912ba6b35/library/core/src/ptr/mod.rs:188:1
  10: iced_wgpu::quad::Pipeline::draw
             at ./wgpu/src/quad.rs:246:13
  11: iced_wgpu::backend::Backend::flush
             at ./wgpu/src/backend.rs:125:13
  12: iced_wgpu::backend::Backend::present
             at ./wgpu/src/backend.rs:89:13
  13: integration_wgpu::main::{{closure}}::{{closure}}
             at ./examples/integration_wgpu/src/main.rs:199:29
  14: iced_graphics::renderer::Renderer<B>::with_primitives
             at ./graphics/src/renderer.rs:40:9
  15: integration_wgpu::main::{{closure}}
             at ./examples/integration_wgpu/src/main.rs:198:25
  16: winit::platform_impl::platform::sticky_exit_callback
             at /home/nlevy/.cargo/git/checkouts/winit-57d3141eaf559308/1e6623c/src/platform_impl/linux/mod.rs:753:5
  17: winit::platform_impl::platform::x11::EventLoop<T>::run_return
             at /home/nlevy/.cargo/git/checkouts/winit-57d3141eaf559308/1e6623c/src/platform_impl/linux/x11/mod.rs:310:21
  18: winit::platform_impl::platform::x11::EventLoop<T>::run
             at /home/nlevy/.cargo/git/checkouts/winit-57d3141eaf559308/1e6623c/src/platform_impl/linux/x11/mod.rs:388:9
  19: winit::platform_impl::platform::EventLoop<T>::run
             at /home/nlevy/.cargo/git/checkouts/winit-57d3141eaf559308/1e6623c/src/platform_impl/linux/mod.rs:669:56
  20: winit::event_loop::EventLoop<T>::run
             at /home/nlevy/.cargo/git/checkouts/winit-57d3141eaf559308/1e6623c/src/event_loop.rs:154:9
  21: integration_wgpu::main
             at ./examples/integration_wgpu/src/main.rs:102:5
  22: core::ops::function::FnOnce::call_once
             at /rustc/59eed8a2aac0230a8b53e89d4e99d55912ba6b35/library/core/src/ops/function.rs:227:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

The problem is that, AFAIK it is not possible to get a Result when trying to draw with wgpu. It is however possible to set a different error handler for validation errors.

@hecrj hecrj force-pushed the master branch 2 times, most recently from e6ab610 to 8b0f2e6 Compare January 19, 2022 15:04
@hecrj hecrj force-pushed the fix_wgpu_integration branch from e2d6d2d to 0412718 Compare September 26, 2022 13:44
Copy link
Member

@hecrj hecrj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for giving this a shot! 🙇

I was able to identify the problem and came up with a simpler fix. We can just recreate the Viewport during RedrawRequested after a resize.

I don't believe there is a consistent way to eliminate the validation errors caused by a mismatch between window and surface dimensions. They were present with your previous changes and are still present now.

In any case, at least the example should not crash now when resizing quickly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working rendering shell wgpu
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants