1

I am getting segmentation fault when I call glGenVertexArrays():

#include <GL/glew.h>

int main()
{
    // Initialize GLEW
    glewExperimental = GL_TRUE;
    glewInit();
    GLuint vao;
    glGenVertexArrays(1, &vao);
}

Answers to such problem suggest setting glewExperimental to true, but this is already set in my code.

genpfault
  • 51,148
  • 11
  • 85
  • 139
robert
  • 3,539
  • 3
  • 35
  • 56
  • 4
    You have to [Create an OpenGL Context](https://www.khronos.org/opengl/wiki/Creating_an_OpenGL_Context_(WGL)), see also [Undefined reference when using glew and mingw?](https://stackoverflow.com/questions/45473091/undefined-reference-when-using-glew-and-mingw) – Rabbid76 Dec 01 '17 at 17:43
  • 1
    Thank you. Creating the window solved the problem. – robert Dec 01 '17 at 18:03

1 Answers1

0

After verifying that glewInit() returned GLEW_OK ask GLEW if the current GL context supports VAOs before attempting to use them via:

  • A core version check (VAOs have been a core feature since GL 3.0):

    if(GLEW_VERSION_3_0)
    {
        // do VAO stuff
    }
    
  • Or by checking for ARB_vertex_array_object extension support:

    if(GLEW_ARB_vertex_array_object)
    {
        // do VAO stuff
    }
    

Otherwise if glewInit() failed or if VAOs aren't supported then GLEW-declared function pointers like glGenVertexArrays will remain NULL and segfault when you try to call them.

genpfault
  • 51,148
  • 11
  • 85
  • 139