-
-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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
WebGPU backend leaks when using ImGui::Image #8027
Comments
Should I propose a PR ? |
Yes that would be good. One that possibly tackle this and #7765 (if meaningful you can split in multiple commits). Note that it is legal for other backends call RenderDrawData() multiple time so I wouldn't perform any clear there. |
Ok, so I could tackle both issues. I tried implementing the solution you proposed in #7765 (comment), in order to remove the permanent storage of So the solution I went with keeps the permanent storage but clears it in As for a global explanation, I think it is pretty clear in #7765 but I can try to sum it up here. In the backend, we provide a way to draw a texture via its N.B: PR incoming, I just wanted to post this before |
Version/Branch of Dear ImGui:
Version 1.90.4, Branch: docking
Back-ends:
imgui_impl_wgpu.cpp + imgui_impl_glfw.cpp
Compiler, OS:
Windows 10 + clang-cl 18.1.8
Full config/build information:
Details:
Whenever an ImGui::Image is used with WebGPU backend, memory leaks are reported
Here is the output I get when running the minimal code sample and closing the window:
As soon as I comment the
ImGui::Image
line, this log disappears.Investigation
I investigated the
imgui_impl_wgpu.cpp
file and it appears that theWGPUBindGroup
s contained inImageBindGroups
(of theRenderResources
structure) are not released instatic void SafeRelease(RenderResources& res)
, that is called byImGui_ImplWGPU_Shutdown()
.Initially, I stumbled upon this while having the issue mentioned reported in #7765. It appears that clearing the
WGPUBindGroup
s each frame could also solve the issue, if it is done at the end of the call toImGui_ImplWGPU_RenderDrawData
, but I think the groups need to survive longer than this. Anyway, theSafeRelease
functions still do not do their job properly.That's why I chose to open a distinct issue.
Local hack to fix the issue
Locally, I hacked my way through the issue but in a very ugly way. I expose the code here in order to show my way of thinking about this issue:
Fix proposal
I do believe that adding some cleaning code in
SafeRelease
would fix the issue in a clean way, something that would look like that:Note that we avoid releasing twice the
WGPUBindGroup
that is both stored inImageBindGroup
andImageBindGroups
. This bind group is used for the default font atlas and is correctly released. When callingImGui::ShowDemoWindow()
, there is no leak because the only call toImGui::Image
is to display the default font atlas.Screenshots/Video:
No response
Minimal, Complete and Verifiable Example code:
The text was updated successfully, but these errors were encountered: