Skip to content

Access violation on the line of glBufferSubData() #4825

Closed
@neo-mashiro

Description

@neo-mashiro

Version/Branch of Dear ImGui:

Version: v1.86
Branch: master

Back-end/Renderer/Compiler/OS

Back-ends: imgui_impl_opengl3.cpp + imgui_impl_glfw.cpp
Compiler: MSVC
Operating System: Windows 10

Hi, I've been having this problem for a long time on my GTX 1050 Ti card, when line 428 below gets called, access violation occurs. Today I just tried the newest version 1.86 where glBufferData() was changed to glBufferSubData(), but the error is still there. I cannot find anything wrong such as null pointers in cmd_list->VtxBuffer, I searched a lot on google and also updated my driver, still no luck.

// Render command lists
for (int n = 0; n < draw_data->CmdListsCount; n++)
{
const ImDrawList* cmd_list = draw_data->CmdLists[n];
// Upload vertex/index buffers
glBufferData(GL_ARRAY_BUFFER, (GLsizeiptr)cmd_list->VtxBuffer.Size * (int)sizeof(ImDrawVert), (const GLvoid*)cmd_list->VtxBuffer.Data, GL_STREAM_DRAW);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, (GLsizeiptr)cmd_list->IdxBuffer.Size * (int)sizeof(ImDrawIdx), (const GLvoid*)cmd_list->IdxBuffer.Data, GL_STREAM_DRAW);

Here is a minimal example that reproduces the error:

glfwInit();
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 6);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
glfwWindowHint(GLFW_SAMPLES, 4);
glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, GLFW_TRUE);
window_ptr = glfwCreateWindow(width, height, title.c_str(), NULL, NULL);
glfwMakeContextCurrent(window_ptr);
glfwSwapInterval(0);

gladLoadGLLoader((GLADloadproc)glfwGetProcAddress);

ImGui::CreateContext();
ImGui_ImplGlfw_InitForOpenGL(Window::window_ptr, false);
ImGui_ImplOpenGL3_Init();

// register callbacks manually .....

while (true) {
    glClearColor(0.0f, 0.0f, 1.0f, 1.0f);
    glClearDepth(1.0f);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    ImGui_ImplOpenGL3_NewFrame();
    ImGui_ImplGlfw_NewFrame();
    ImGui::NewFrame();

    ImGui::Text("test");  // doesn't matter what we draw

    ImGui::Render();
    ImGui_ImplOpenGL3_RenderDrawData(GetDrawData());  // access violation inside this call

    glfwSwapBuffers(Window::window_ptr);
    glfwPollEvents();
}

I'm not sure if this is a problem of ImGui, just wonder if people have reported similar issues or solutions on this. It looks like a driver issue because it only happens on my NVIDIA 1050 ti card, but works fine on AMD 540 and Intel HD 620. The weird thing is that, this access violation is gone when I try to debug the app in RenderDoc, as long as I run it through RenderDoc, everything work as expected, but of course I can't debug line by line then.....

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions