pixels icon indicating copy to clipboard operation
pixels copied to clipboard

Bump dependencies for imgui-winit example

Open mkrasnitski opened this issue 1 year ago • 2 comments

imgui-wgpu-rs now supports wgpu 0.19 and winit 0.29, but only on the git HEAD. A release hasn't been cut yet so keeping this as draft for now. Also, resizing the window now crashes the app with the following error:

wgpu error: Validation Error

Caused by:
    In a RenderPass
      note: encoder = `pixels_command_encoder`
    In a set_scissor_rect command
    Scissor Rect { x: 0, y: 0, w: 642, h: 483 } is not contained in the render target (640, 480, 1)

I figured this PR would be a good place to track this while the root cause is figured out.

mkrasnitski avatar Sep 23 '24 19:09 mkrasnitski

The validation error is from desynchronized draw and resize. Resize is deferred by winit-input-helper, but drawing is not.

It can be fixed by reordering these operations. E.g. by moving the drawing code after the resize, but before the world.update() call. Or alternatively and preferably, move the resize out of the input.update() guard and use the normal winit event matching instead.

Sigh. These are some skeletons in the closet. The history here is sort of documented in https://github.com/parasyte/pixels/issues/270#issuecomment-1092627678.

I ended up matching on the event for RedrawRequested separately from using input.update()'s return value for some of the reasons described there. We kind of got away with it, but these events should not be deferred.

Deferring these events causes problems like the resize looking horrible while the user drags the window frame around. The intermediate frame gets stretched and warped. The right way to handle resize will correctly redraw every frame while the resize is in progress. And doing that means no deferral of resize and redraw events.

And yeah, deferring events is what you are expected to do with winit-input-helper: https://github.com/rukai/winit_input_helper/blob/106e033c718ccfb346866c054d23025666ae13ae/examples/example.rs#L33-L35

So, it's probably time for it to go.

parasyte avatar Sep 23 '24 21:09 parasyte

I'm also completely misremembering how it ended up that RedrawRequested is treated differently from the rest of the event handling. Because this was there since the beginning with a salient comment:

https://github.com/parasyte/pixels/blob/17c6054f40daf0a77544994c4d0e46ae4fe258d0/examples/invaders/main.rs#L34-L38

All of the examples inherited it.

parasyte avatar Sep 23 '24 22:09 parasyte