Yatekii / imgui-wgpu-rs

Dear imgui renderer for wgpu-rs.
MIT License
256 stars 84 forks source link

Update imgui dependency to version 0.7.0 #44

Closed 4bb4 closed 3 years ago

4bb4 commented 3 years ago

Hi there,

I use imgui-wgpu-rs over at https://github.com/4bb4/implot-rs, and after the recent upgrade of imgui-rs to 0.7, I'd like to also use the WGPU with it. I hence tried out bumping the versions in imgui-wgpu-rs and things seem to work somewhat (the code builds, anyway). Let me know what you think.

One thing I did encounter in my example code that uses WGPU (https://github.com/4bb4/implot-rs/tree/13-upgrade-to-imgui-rs-0.7/implot-examples/implot-wgpu-demo) is that once I point things to wgpu 0.7 and the version of imgui-wgpu-rs that is the source of this PR, things run, but once I scroll around a bit in a window, I get a panic:

wgpu error: Validation Error

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

thread 'main' panicked at 'Handling wgpu errors as fatal by default', .../.cargo/registry/src/github.com-1ecc6299db9ec823/wgpu-0.7.0/src/backend/direct.rs:1896:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
thread 'main' panicked at 'assertion failed: `(left == right)`
  left: `1`,
 right: `0`: Allocator dropped before all sets were deallocated', .../.cargo/registry/src/github.com-1ecc6299db9ec823/gpu-descriptor-0.1.0/src/allocator.rs:117:9

I'm not expecting anyone to fix my problems for me, but I thought this might be a problem not specific to my example but rather with just bumping versions like I do in this PR. I can provide a full stack trace or try other stuff as well if desired.

Yatekii commented 3 years ago

Hi!

The update is already done: https://github.com/Yatekii/imgui-wgpu-rs/pull/43

Have fun :)

cwfitzgerald commented 3 years ago

My PR only updated wgpu-rs not imgui-rs, that hasn't released at the time. Reopening

Yatekii commented 3 years ago

Ohhh, I am sorry :/ Silly me ...

cwfitzgerald commented 3 years ago

Sorry, I didn't realize this PR was already in flight when I did #46. Could you refile your issue as an issue and I'll try to address this.

francesco-cattoglio commented 3 years ago

Hi @4bb4 The same panic just happened to me today, and I am writing this short summary hoping it might be useful to you (or anyone else). Inside my winit loop I do the standard handling of events, including handling ResizeEvent() by letting imgui_winit_support::WinitPlatform handle the events first and then processing them on my side, creating a new swapchain if necessary. HOWEVER, some time ago I was experiencing crashes due to wgpu::SwapChainError::Outdated errors, and to solve those I added some code that would re-create the swapchain on-the-fly if this error appeared. This however means that now the WinitPlatform is not able to tell imgui about the new sizes. Now there is a size mismatch between what imgui thinks is the framebuffer and the actual size of the framebuffer, and this is what causes the Invalid ScissorRect parameters error. This was not a hard error before wgpu 0.7, I think it was just simply ignored. To solve this problem, I have to just ignore the SwapChainError::Outdated error: if that happens I just skip rendering altogether for one frame.

4bb4 commented 3 years ago

@francesco-cattoglio thanks so much for letting me know! I'll try out that solution.

benmkw commented 3 years ago

I tried to investigate and arrived at this example https://github.com/benmkw/implot-rs/commit/17abc3c8e6e0918cb0c5068be197542bb2937165#diff-e6ddd2ce7261a8499a67a68c28586ca5722e6410972f3651a8d26805d9e94e43R16

If you uncomment that line and expand the two dropdowns, it crashes.

4bb4 commented 3 years ago

@benmkw,

If you uncomment that line and expand the two dropdowns, it crashes.

Was this with @francesco-cattoglio's fixes applied already or without?

benmkw commented 3 years ago

I did not see if/ how those apply to this crash/ could not see a similar code path, I looked at the scissor rect code in imgui-wgpu-rs and suspected an off by one error but did not find one yet :D So my next best bet is that the queue which we get from imnodes might have an issue but this also seems rather unlikely.

4bb4 commented 3 years ago

Alright, thanks for letting me know and minimising the crash. That'll help me when I get around to investigating.