3

I use GLAD (config) to load OpenGL functions and GLFW 3.3.8 to create context. Each time I start my program it pops a ERROR 1282 in glGetIntegerv from GLAD debug post-callback function (as far as I know it is invoked after each gl- function and prints an error if any occurred). I figured that this happens after returning from main().

Here's the code (it loads OpenGL 3.3 and shows red window until it is closed, pretty simple I think):

#include <iostream>
#include <glad/glad.h>
#include <GLFW/glfw3.h>

int main()
{
    if(glfwInit() != GLFW_TRUE)
        throw std::runtime_error{"Unable to initialize GLFW."};

    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
    glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
    GLFWwindow * w{glfwCreateWindow(100, 100, "title", nullptr, nullptr)};
    if(w == nullptr)
        throw std::runtime_error{"Unable to create window."};

    glfwMakeContextCurrent(w);
    if(not gladLoadGLLoader(GLADloadproc(glfwGetProcAddress)))
        throw std::runtime_error{"Unable to load OpenGL functions."};
    
    glViewport(0, 0, 100, 100);

    while(not glfwWindowShouldClose(w))
    {
        glfwPollEvents();

        glClearColor(1.f, 0.f, 0.f, 1.f);
        glClear(GL_COLOR_BUFFER_BIT);
        
        glfwSwapBuffers(w);
    }

    glfwMakeContextCurrent(nullptr);
    glfwDestroyWindow(w);
    glfwTerminate();

    std::cout << "Hey!" << std::endl;
    return 0;
}

The output is:

Hey!
ERROR 1282 in glGetIntegerv

From this callstack:

#0  0x00416f91 in _post_call_callback_default_gl (name=0x446d40 <_glfwDataFormat+10036> "glGetIntegerv", funcptr=0x41c1ec <glad_debug_impl_glGetIntegerv@8>, len_args=2) at <glad.c>:45
#1  0x0041c265 in glad_debug_impl_glGetIntegerv@8 (arg0=33309, arg1=0x4526cc <num_exts_i>) at <glad.c>:1385
#2  0x00417168 in get_exts () at <glad.c>:220
#3  0x0042691f in find_extensionsGL () at <glad.c>:3742
#4  0x00426d12 in gladLoadGLLoader (load=0x402a2e <glfwGetProcAddress>) at <glad.c>:3821
#5  0x004016f8 in main () at <main.cpp>:33

Error 1282 is GL_INVALID_OPERATION, but it pops up after the program ended (or at least after the main() ended). Even if I separate the whole code in another function (i. e. create and destroy everything in separate function), and then invoke it in main(), the error still appears after the return 0; from main().

This did not happen when I used GLEW to load OpenGL functions, but maybe it was silenced. I didn't find anything similar to my problem on the internet. What am I doing wrong? Do I have to unload OpenGL or something like that?

UPD: Error message actually pops in gladLoadGLLoader(), not after the end of main().

genpfault
  • 51,148
  • 11
  • 85
  • 139
  • Can't repro on a Debian Bullseye box with Mesa 22.0.4 on a Radeon RX 6700 XT under X11. What are you trying to run this on? – genpfault Jan 01 '23 at 06:04
  • 1
    @genpfault Windows 10 x64, Strix 1080Ti (no overclock or anything), latest GeForce Experience drivers. I also tried this code on another PC with same Windows and ASUS 1060, error does not pop there. Seems to be deeper than just faulty code. – postcoital.solitaire Jan 01 '23 at 18:48
  • Wouldn't be surprised if it's glad's error handling callback that somehow triggers a gl function after the context has been deleted. Have you tried to add a call to gladLoaderUnloadGL before exiting? – StarShine Jan 01 '23 at 23:52
  • @StarShine Didn't know such thing as `gladLoaderUnloadGL` exists, moreover it is not included in my generated GLAD code. Anyway, the error occurres on `gladLoadGLLoader()` i. e. when GL is being loaded (or more precicely when `glGetIntegerv(GL_NUM_EXTENSIONS)` is called in GLAD loader), so doing anything after the fact must not have any affect on the error. – postcoital.solitaire Jan 02 '23 at 00:19
  • Ah seems I missed that last line in your post :) In which case you're right. It looks like this is GLAD debug version, maybe some asserts trigger that do not in release mode? – StarShine Jan 02 '23 at 00:49
  • 1
    @StarShine Nah, the error is raised anyway (the code where this happens is the same), it's just not tested with `glGetError()` like it would in debug version. And also the fact that this does not happen on another PC (genpfault did not reproduce it and I did not see this on another machine) suggests that it's some sort of hardware / driver / other issue — **not** the GLAD fault. – postcoital.solitaire Jan 02 '23 at 01:01

0 Answers0