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

Error imgui GLSL 4.40 #2421

Closed
Zukhruf opened this issue Mar 15, 2019 · 16 comments
Closed

Error imgui GLSL 4.40 #2421

Zukhruf opened this issue Mar 15, 2019 · 16 comments

Comments

@Zukhruf
Copy link

Zukhruf commented Mar 15, 2019

Version: 1.69
Branch: master

Back-end/Renderer/Compiler/OS

Back-ends: imgui_impl_opengl3.cpp + imgui_impl_sdl.cpp
Compiler: Visual Studio, C++ 11
Operating System: windows 10

My Issue/Question:

I Try to add GUI on my animation engine program. But when adding ImGui for opengl3 sdl2, I always have error at glGetIntegerv(GL_ARRAY_BUFFER_BINDING, &last_array_buffer);, and the error says, Access violation executing location 0x0000000000000000. Before adding imgui, my program works fine. I search some solution on the internet, but none of those are works.

Screenshots/Video
image

Standalone, minimal, complete and verifiable example:

bool    ImGui_ImplOpenGL3_CreateDeviceObjects()
{
    // Backup GL state
    GLint last_texture, last_array_buffer;
    glGetIntegerv(GL_TEXTURE_BINDING_2D, &last_texture);
    glGetIntegerv(GL_ARRAY_BUFFER_BINDING, &last_array_buffer); <-- Error at this line
#ifndef IMGUI_IMPL_OPENGL_ES2
    GLint last_vertex_array;
    glGetIntegerv(GL_VERTEX_ARRAY_BINDING, &last_vertex_array);
#endif 
}
@ocornut
Copy link
Owner

ocornut commented Mar 15, 2019

You have probably not initialized the GL functions pointers of the GL function loaders that is used by imgui_impl_opengl3.cpp (by default we use gl3w)

ocornut added a commit that referenced this issue Mar 15, 2019
…L3_Init() to detect uninitialized GL function loaders early, and help users understand what they are missing. (#2421)
@ocornut
Copy link
Owner

ocornut commented Mar 15, 2019

I made a few changes to imgui_impl_opengl3.cpp to help users understand what they have made this mistake of not initializing the GL function loader.

Please refer to the examples/ main.cpp files for a working application.

@ocornut ocornut closed this as completed Mar 15, 2019
@Jaumeavinyo
Copy link

Hi! have a similar problem with gladLoadGL() wich now i sopose it is called gladLoadGLLoader() as I can see in glad.c. My problem is a access violation with the variable "last_active_texture". the thing is that after adding gladloader in my code, The problem persist

ERROR HERE
gladLoadGL screenshot

@ocornut
Copy link
Owner

ocornut commented Jul 8, 2021

@Jaumeavinyo What's your version and the most recent date at the top of your imgui_impl_opengl3.cpp ?
Can you step in ImGui_ImplOpenGL3_Init() and confirm the values of GlVersion and the value of the gl_loader string defined near the end of that function?

@Jaumeavinyo
Copy link

I downloaded the 1.81 imGui release from your repo. The most recent date in the change log of the file imgui_impl_opengl3.cpp is:
// 2021-XX-XX: Platform: Added support for multiple windows via the ImGuiPlatformIO interface.
// 2021-01-03: OpenGL: Backup, setup and restore GL_STENCIL_TEST state.

the glsl version string is: "#version 130" and the value of the gl_loader string is unknown because I don't really think I understand where does the inside function of the loader get the string from

image here

@Jaumeavinyo
Copy link

pd: thanks for the hyper fast attention to my post!

@ocornut
Copy link
Owner

ocornut commented Jul 8, 2021

The code in ImGui_ImplOpenGL3_Init() has this block:

    // Debugging construct to make it easily visible in the IDE and debugger which GL loader has been selected.
    // The code actually never uses the 'gl_loader' variable! It is only here so you can read it!
    // If auto-detection fails or doesn't select the same GL loader file as used by your application,
    // you are likely to get a crash below.
    // You can explicitly select a loader by using '#define IMGUI_IMPL_OPENGL_LOADER_XXX' in imconfig.h or compiler command-line.
    const char* gl_loader = "Unknown";
    IM_UNUSED(gl_loader);
#if defined(IMGUI_IMPL_OPENGL_LOADER_GL3W)
    gl_loader = "GL3W";
#elif defined(IMGUI_IMPL_OPENGL_LOADER_GLEW)
    gl_loader = "GLEW";
#elif defined(IMGUI_IMPL_OPENGL_LOADER_GLAD)
    gl_loader = "GLAD";
#elif defined(IMGUI_IMPL_OPENGL_LOADER_GLAD2)
    gl_loader = "GLAD2";
#elif defined(IMGUI_IMPL_OPENGL_LOADER_GLBINDING2)
    gl_loader = "glbinding2";
#elif defined(IMGUI_IMPL_OPENGL_LOADER_GLBINDING3)
    gl_loader = "glbinding3";
#elif defined(IMGUI_IMPL_OPENGL_LOADER_CUSTOM)
    gl_loader = "custom";
#else
    gl_loader = "none";
#endif

You want to step at the end of this block and check the exact version for gl_loader. If it isn't "GLAD" or "GLAD2" then the compile-time configuration is wrong and the backend doesn't know about your loader so it's going to try accessing the function symbols from another loader which wasn't initialized.

@Jaumeavinyo
Copy link

Here you have it. Thanks

// Debugging construct to make it easily visible in the IDE and debugger which GL loader has been selected.
// The code actually never uses the 'gl_loader' variable! It is only here so you can read it!
// If auto-detection fails or doesn't select the same GL loader file as used by your application,
// you are likely to get a crash below.
// You can explicitly select a loader by using '#define IMGUI_IMPL_OPENGL_LOADER_XXX' in imconfig.h or compiler command-line.
const char* gl_loader = "Unknown";
IM_UNUSED(gl_loader);
#if defined(IMGUI_IMPL_OPENGL_LOADER_GL3W)
gl_loader = "GL3W";
#elif defined(IMGUI_IMPL_OPENGL_LOADER_GLEW)
gl_loader = "GLEW";
#elif defined(IMGUI_IMPL_OPENGL_LOADER_GLAD)
gl_loader = "GLAD";
#elif defined(IMGUI_IMPL_OPENGL_LOADER_GLAD2)
gl_loader = "GLAD2";
#elif defined(IMGUI_IMPL_OPENGL_LOADER_GLBINDING2)
gl_loader = "glbinding2";
#elif defined(IMGUI_IMPL_OPENGL_LOADER_GLBINDING3)
gl_loader = "glbinding3";
#elif defined(IMGUI_IMPL_OPENGL_LOADER_CUSTOM)
gl_loader = "custom";
#else
gl_loader = "none";
#endif

@Jaumeavinyo
Copy link

Im using:
gl_loader = "GLAD"

@ocornut
Copy link
Owner

ocornut commented Jul 8, 2021

Your first answer suggest you are misunderstanding my question.
Please use a debugger or add a printf() statement to actually confirm that the runtime value of gl_loader is GLAD.

If you didn't properly set the compile-time option IMGUI_IMPL_OPENGL_LOADER_GLAD or IMGUI_IMPL_OPENGL_LOADER_GLAD2 then the backend code is going to try to detect a loader based on available includes but there's no guarantee it's going to pick the same one ("glad") as you initialized.

@Jaumeavinyo
Copy link

here you have it, debuuged and confirmed

@ocornut
Copy link
Owner

ocornut commented Jul 8, 2021

You didn't gave me the GlVersion version, only the GLSLversion one.

@Jaumeavinyo
Copy link

You didn't gave me the GlVersion version, only the GLSLversion one.

where do I find this=?

@Jaumeavinyo
Copy link

You didn't gave me the GlVersion version, only the GLSLversion one.

here?¿

@ocornut
Copy link
Owner

ocornut commented Jul 8, 2021

In your version of the code there's a variable g_GlVersion setup at the beginning of ImGui_ImplOpenGL3_Init()
I am afraid I can't help further if you are not researching things further and not reading comments.

Also your first screen has some code saying glPushDebugGroup() which is not part of vanilla imgui_impl_opengl3 and was never part of it, and it looks like it may be this function call that crash. So you are using a modified backend so at this point I can't really help debugging random modified code that wasn't provided nor have a justification.

@Jaumeavinyo
Copy link

Jaumeavinyo commented Jul 8, 2021

In your version of the code there's a variable g_GlVersion setup at the beginning of ImGui_ImplOpenGL3_Init()
I am afraid I can't help further if you are not researching things further and not reading comments.

Also your first screen has some code saying glPushDebugGroup() which is not part of vanilla imgui_impl_opengl3 and was never part of it, and it looks like it may be this function call that crash. So you are using a modified backend so at this point I can't really help debugging random modified code that wasn't provided nor have a justification.

Okay, you helped a lot, don'tworry I just needed some clues to find where was the problem, pd, my gl version is 320

pd, glPushDebugGroup() is not something I added to the code. I will review what happened thanks

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

No branches or pull requests

3 participants