Skip to content
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

Possible memory leak. opengl3 #2981

Closed
TheHiddenDuke opened this issue Jan 15, 2020 · 5 comments
Closed

Possible memory leak. opengl3 #2981

TheHiddenDuke opened this issue Jan 15, 2020 · 5 comments

Comments

@TheHiddenDuke
Copy link

Version/Branch of Dear ImGui:

Version: 1.72 WIP
Branch: master

Back-end/Renderer/Compiler/OS

Back-ends: imgui_impl_opengl3.cpp
Compiler: llvm
Operating System: VxWorks 7

My Issue/Question:

I'm using the function to add primitives to the draw list for a single window. This renders the gui perfect, but there seems to be a memory leak as after 2 hours of running continuously the system crashes due to the lack of ram.

Here is the code used to initialize build up the screen. Only one window is used as a "canvas" to place all the primitives on. At most there is close to 300 objects that are drawn inside the draw_list.

gfxDisplay disp;
disp.init();

auto [width, height] = disp.getResolution();

auto [eglMajor, eglMinor] = disp.getVersion();

auto[a, b, g, r] = rgba(GetColor(TRANSPARENT));

glClearColorIuiEXT(r, g, b, a);

glEnable(GL_DEPTH);

height = std::max(1, height);

glViewport(0, 0, width, height);

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-3.0, 3.0, -3.0, 3.0, 1.0, 10000.0);

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

const char* glsl_version = "#version 130";

IMGUI_CHECKVERSION();
ImGui::CreateContext();
ImGuiIO& io = ImGui::GetIO();
(void)io;

ImGui::StyleColorsDark();

ImGui_ImplOpenGL3_Init(glsl_version);

while(running)
{
  ImGui_ImplOpenGL3_NewFrame();
  ImGui_ImplVxWorks_NewFrame();
  ImGui::NewFrame();

  ImGui::Begin("main", NULL, ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoResize | 
  ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_NoMove | 
  ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoScrollbar);

    draw_list = ImGui::GetWindowDrawList();
    /* Call to multiple add functions, Addline, AddBezierCurve, PathArcTo, AddRectFilled, AddRect 
    andAddText */ 

     draw_list->AddLine(ImVec2(startX-(lineWidth/2), startY-(lineWidth/2)), 
                                     ImVec2(endX-(lineWidth/2), endY-(lineWidth/2)), 
                                     col, 
                                     lineWidth);
  ImGui::End();
  ImGui::Render();
  glClearColor((r / maxRGB), (g / maxRGB), (b / maxRGB), a);

  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

  ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());

  disp.swapBuffer();
}
ImGui_ImplOpenGL3_Shutdown();
ImGui_ImplVxWorks_Shutdown();
ImGui::DestroyContext();

Hope someone can give some insight!

@ocornut
Copy link
Owner

ocornut commented Jan 15, 2020

There hasn't been a leak in ImDrawList since release afaik - we only keep buffer allocated accross frames but that doesn't accumulate.

So your issue is either:

  1. There is an ever growing amount of content in the code you ommited "call to multiple add functions...". You can use the Metrics window to inspect what you are submitting.
  2. There is an issue with your GL driver weere buffers are not recycled/freed properly (considering you are using a rather obscure OS that's not unlikely, GL drivers even under Windows are frequently bugged)
  3. There is an issue with your VxWorks code which seems to be third-party code (is that code available).

Note that you could perfectly run your loop without any of the GL/VX code, only NewFrame+Begin/End/DrawList stuff/Render at a much faster speed and confirm if you get a leak which would mean the issue is in 1) not in 2) or 3). Similarly to could skip the GL rendering completely (removed glClear, RenderDrawData, swapBuffer) etc.

Either way until proven it doesn't seem like some code in the dear imgui repository is faulty.

@TheHiddenDuke
Copy link
Author

Thank you for a quick reply and a descriptive answer!

I forgot to mention that I did run ImGui on windows without any sign of the memory leak, as well as I checked the Metrics window and it kept the same values. So I also doubt that dear imgui is the reason.

I don't really know a lot about openGl and how it interacts with imgui.
Would you have an idea of where to start looking?

@ocornut
Copy link
Owner

ocornut commented Jan 15, 2020 via email

@ocornut
Copy link
Owner

ocornut commented Jan 15, 2020

Closing this because out of our support scope.

@ocornut ocornut closed this as completed Jan 15, 2020
ocornut added a commit that referenced this issue Dec 15, 2021
…to fix leaks with multi-viewports with some Intel HD drivers.. (#4468, #4504, #2981, #3381)
ocornut added a commit that referenced this issue May 23, 2022
…ta(): now only done on Intel GPUs. (#4468, #3381, #2981, #4825, #4832, #5127)

Essentially reverts 389982e for non-Intel GPUs + update imgui_impl_opengl3_loader.h
ocornut added a commit that referenced this issue May 23, 2022
…ta(): now only done on Intel GPUs. (#4468, #3381, #2981, #4825, #4832, #5127)

Essentially reverts 389982e for non-Intel GPUs + update imgui_impl_opengl3_loader.h
Amended once (force-pushed).
ocornut added a commit that referenced this issue May 30, 2022
…4825, #4832, #5127)

# Conflicts:
#	backends/imgui_impl_opengl3.cpp
@ocornut
Copy link
Owner

ocornut commented Nov 9, 2022

Reverted the changes of #4468 with b8b0f9d, not using glBufferSubData() anymore.
PLEASE REPORT IF YOU STILL HAVE ISSUES AFTER TODAY.
I temporarily kept the alternative code path even though bd->UseBufferSubData is always false, allowing potential experiment shall new issues arises. Finger crossed this doesn't bite us back.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants