iced
iced copied to clipboard
Fix wgpu integration example
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.
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.
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/github.com-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/github.com-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/github.com-1ecc6299db9ec823/wgpu-0.11.1/src/backend/direct.rs:2183:9
6: wgpu::backend::direct::Context::handle_error
at /home/nlevy/.cargo/registry/src/github.com-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/github.com-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/github.com-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.