Member Avatar

I am in the process of making a small game-engine for educational purposes, and I have come accross a very fustrating error. When debugging the program with the c++ gdb debugger an error occurs on the glGenVertexArrays(0, &m_vertexArrayObject); - line 21 in the implementation of the addVertices method, line in the second code extract. I searched for possible reasons and solutions on the internet and the answer I got was that I was making a mistake with pointers or uninitialized variables.

The debugger gives a

What am I doing wrong? I can post the full source on google drive and supply a link if needed.

//The call to the function giving the error:

Core::Core( int w, int h, std::string& title ):
    running(false), width(w), height(h), m_title(title), game()
    this->m_window = new Window(800, 600, "GameEngineCore");

    mesh = new Mesh();   //the mesh class pointer is stored as a private class variable
    mesh->addVertices(data, 3);

//The actual function causing the error:

void Mesh::addVertices(Vertex* vertices, unsigned int numVerts){
    m_size = numVerts; // * Vertex::SIZE;

    glGenVertexArrays(0, &m_vertexArrayObject);   //error occurs here 

        //place and bind vertices onto gpu memory
        glGenBuffers(NUM_BUFFERS, m_vertexArrayBuffers);  
        glBindBuffer(GL_ARRAY_BUFFER, m_vertexArrayBuffers[POSITION_VB]); 
        glBufferData(GL_ARRAY_BUFFER, numVerts*sizeof(vertices[0]), &vertices[0], GL_STATIC_DRAW); 

        glEnableVertexAttribArray(0); //divides data into attributes //only 1 attribute
        glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0); 


//constructor of the Mesh class


//private variables of the Mesh class


GLuint m_vertexArrayObject; //vertex array object - reference to mesh data
GLuint m_vertexArrayBuffers[NUM_BUFFERS]; //array of vertex array objects
unsigned int m_size;
Member Avatar

Yes, I am using GLEW for my opengl functions.

Member Avatar

Thanks a lot! A combination of that fix in SO and instantiating the game class after the window class fixed the error. I really appreciate the help. Struggled with this problem to no end