Access Violation Error ImGui_Impl_OpenGL3 #3986

Closed
opened 2021-03-29 14:20:03 +00:00 by romainaugier · 5 comments
romainaugier commented 2021-03-29 14:20:03 +00:00 (Migrated from github.com)

ImGui Docking Branch, version 1.82 WIP // ImGui GLFW and OpenGL 3 // MSVC // WIN32

Hello, I'm running into an issue I've never had before. When I run my program on my home computer, everything works fine, but I cloned my repository at school and when I start the program I have an error : Access violation executing location in imgui_impl_opengl3.cpp at line 682.

I can confirm ImGui and OpenGL works on the computer I tried because when I run an older version of my program, it works fine.

Here's a screenshot of the debugger
image

And here is my code (copied from the ImGui_Impl_openGL3 example)

// Setup window
    glfwSetErrorCallback(glfw_error_callback);
    if (!glfwInit())
        return 1;


    // GL 3.0 + GLSL 130
    const char* glsl_version = "#version 130";
    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0);
    //glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);  // 3.2+ only
    glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);            // 3.0+ only


    // Create window with graphics context
    GLFWwindow* window = glfwCreateWindow(1920, 1080, "Romano Render", NULL, NULL);
    if (window == NULL)
        return 1;
    glfwMakeContextCurrent(window);
    glfwSwapInterval(1); // Enable vsync

    // Initialize OpenGL loader
    bool err = gl3wInit() != 0;

    if (err)
    {
        fprintf(stderr, "Failed to initialize OpenGL loader!\n");
        return 1;
    }

And last, here is the link to my main file (where the window is implemented)

https://github.com/DonRomanooo/RomanoRender/blob/RomanoRender/RomanoRender/src/Main.cpp

ImGui Docking Branch, version 1.82 WIP // ImGui GLFW and OpenGL 3 // MSVC // WIN32 Hello, I'm running into an issue I've never had before. When I run my program on my home computer, everything works fine, but I cloned my repository at school and when I start the program I have an error : *Access violation executing location* in imgui_impl_opengl3.cpp at line 682. I can confirm ImGui and OpenGL works on the computer I tried because when I run an older version of my program, it works fine. Here's a screenshot of the debugger ![image](https://user-images.githubusercontent.com/57313427/112849339-42d41480-90a9-11eb-8f10-7b6c5c80d67c.png) And here is my code (copied from the ImGui_Impl_openGL3 example) ``` // Setup window glfwSetErrorCallback(glfw_error_callback); if (!glfwInit()) return 1; // GL 3.0 + GLSL 130 const char* glsl_version = "#version 130"; glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0); //glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); // 3.2+ only glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); // 3.0+ only // Create window with graphics context GLFWwindow* window = glfwCreateWindow(1920, 1080, "Romano Render", NULL, NULL); if (window == NULL) return 1; glfwMakeContextCurrent(window); glfwSwapInterval(1); // Enable vsync // Initialize OpenGL loader bool err = gl3wInit() != 0; if (err) { fprintf(stderr, "Failed to initialize OpenGL loader!\n"); return 1; } ``` And last, here is the link to my main file (where the window is implemented) https://github.com/DonRomanooo/RomanoRender/blob/RomanoRender/RomanoRender/src/Main.cpp
ocornut commented 2021-03-29 14:51:14 +00:00 (Migrated from github.com)

First of all please confirm if the unmodified examples/ application work on this machine.

Then you will probably need to step in a debugger and check the different return values and GL errors to try to nail down what's happening.

First of all please confirm if the unmodified examples/ application work on this machine. Then you will probably need to step in a debugger and check the different return values and GL errors to try to nail down what's happening.
romainaugier commented 2021-03-29 15:00:25 +00:00 (Migrated from github.com)

First of all please confirm if the unmodified examples/ application work on this machine.

I copy/pasted the example code in examples/example_glfw_opengl3/main.cpp and overriden the code in my main.cpp to see if it was a mistake I made, but it's not working. From the bit of debugging I tried while waiting for your answer, it seems that glCreateShader() returns 0 which means an error, but I haven't found any more information on this since then.

When I compile and run an older version program, which is using ImGui 1.79 (and not the docking branch), it works fine. The computer has OpenGL 4.6.

> First of all please confirm if the unmodified examples/ application work on this machine. I copy/pasted the example code in examples/example_glfw_opengl3/main.cpp and overriden the code in my main.cpp to see if it was a mistake I made, but it's not working. From the bit of debugging I tried while waiting for your answer, it seems that glCreateShader() returns 0 which means an error, but I haven't found any more information on this since then. When I compile and run an older version program, which is using ImGui 1.79 (and not the docking branch), it works fine. The computer has OpenGL 4.6.
ocornut commented 2021-03-29 15:09:07 +00:00 (Migrated from github.com)

I'm not sure I understand your answer clearly or why you copy/paste example code.
Does running the example application unmodified (as provided in the repository) works?

I'm not sure I understand your answer clearly or why you copy/paste example code. **Does running the example application unmodified (as provided in the repository) works?**
romainaugier commented 2021-03-29 16:11:43 +00:00 (Migrated from github.com)

I just meant that I tried to copied the example code over my existing code to test if the example code was working, and so there was a bug in my implementation.

I tested with the OpenGL3 example and it works fine yes !

I just meant that I tried to copied the example code over my existing code to test if the example code was working, and so there was a bug in my implementation. I tested with the OpenGL3 example and it works fine yes !
ocornut commented 2021-03-29 16:32:42 +00:00 (Migrated from github.com)

I tested with the OpenGL3 example and it works fine yes !

Thank you. Well from this point if it isn't a bug in dear imgui examples nor backends it is an issue in your code and we unfortunately can't really debug your code.

Looking at the first screenshot I would say that your issue is that your GL loader are not initialized and glCreateShader() points to NULL and therefore fails to execute. You need to make sure the loader used by the opengl3 backend has been initialized in your code. But your previous message suggests that glCreateShader() which would contradict this, unless you misunderstood something in the debugger session.

Try to step in ImGui_ImplOpenGL3_Init() and check the value of gl_loader and make sure imgui_impl_opengl3 is using the same GL loader as the one that's initialized by your code.

> I tested with the OpenGL3 example and it works fine yes ! Thank you. Well from this point if it isn't a bug in dear imgui examples nor backends it is an issue in your code and we unfortunately can't really debug your code. Looking at the first screenshot I would say that your issue is that your GL loader are not initialized and `glCreateShader()` points to NULL and therefore fails to execute. You need to make sure the loader used by the opengl3 backend has been initialized in your code. But your previous message suggests that `glCreateShader()` which would contradict this, unless you misunderstood something in the debugger session. Try to step in `ImGui_ImplOpenGL3_Init()` and check the value of `gl_loader` and make sure imgui_impl_opengl3 is using the same GL loader as the one that's initialized by your code.
Sign in to join this conversation.
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
ocornut/imgui#3986
No description provided.