OpenGL: fix per-frame VAO leak in the ImGui GL3 backend - #2463
Merged
flyinghead merged 1 commit intoSep 4, 2026
Merged
Conversation
Owner
|
Good catch on this problem. That might explain a number of OOM errors and GL driver crashes. However your proposed solution brings a new issue: the VAO created is never deleted, even if the GL context is invalidated, the window destroyed and recreated, flycast switches to vulkan and back, etc. It likely will become invalid at some point. |
aldoborrero
force-pushed
the
fix/imgui-gl3-per-frame-vao-leak
branch
from
September 3, 2026 18:55
6c9a8e8 to
1819878
Compare
ImGui_ImplOpenGL3_SetupRenderState generated the VAO into its `vertex_array_object` parameter, which is passed by value, so the name never reached ImGui_ImplOpenGL3_RenderDrawData. There the local was still 0, the `if (vertex_array_object != 0)` guard was false, and glDeleteVertexArrays never ran — a VAO was leaked every frame. The OSD is drawn every frame, so on Mesa (radeonsi) host memory grows unbounded until OOM; Vulkan is unaffected. Move the glGenVertexArrays back into RenderDrawData and pass the handle to SetupRenderState for binding only, so the existing glDeleteVertexArrays runs and the VAO is recreated each frame (staying valid across GL context changes), matching the upstream ImGui backend.
aldoborrero
force-pushed
the
fix/imgui-gl3-per-frame-vao-leak
branch
from
September 3, 2026 19:23
1819878 to
56d3db3
Compare
Contributor
Author
|
Good point, and you're right; I confirmed it by live-switching OpenGL -> Vulkan -> OpenGL. I've updated the PR accordingly. Thanks for your time. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
OpenGL: fix per-frame VAO leak in the ImGui GL3 backend
Fixes #2462.
The bug
ImGui_ImplOpenGL3_SetupRenderStategenerates the VAO into itsvertex_array_objectparameter, which is passed by value:
so the name never reaches the caller,
ImGui_ImplOpenGL3_RenderDrawData, where it is still0:The guard is false,
glDeleteVertexArraysnever runs, and a VAO is leaked every frame.The OSD overlay is drawn every frame, so on Mesa/radeonsi host memory grows unbounded until
OOM (~370–535 MiB/h in my testing). The Vulkan renderer's ImGui backend keeps persistent
buffers and is unaffected — which is the tell.
The fix
Cache the VAO in a single persistent handle (flycast uses one GL context) and drop the dead
delete. The vertex-attrib state is re-established every frame in
SetupRenderState, so asingle reused VAO is correct.
Validation
Built and run on Linux / AMD Radeon 780M (radeonsi), OpenGL:
byte-identical over 10 min. Vulkan already flat, unchanged.
Rendering and the in-emulator ImGui menus verified visually with the cached VAO.
Analysis and reproduction assisted by an AI tool; the patch was built and verified on real hardware. (No LLM policy in this repo — remove if unwanted.)