INVALID OPERATION In my VAO ?

I have an encapsulated VAO that works fine, but the first time I bind it for drawing (not counting creation) I get an INVALID OPERATION error.
Here’s my VBO + VAO creation (in the end of a model loading function)

///Creation du VBO
    if(glIsBuffer(m_VBO))
    glDeleteBuffers(1, &m_VBO);
    glGenBuffers(1, &m_VBO);
    glBindBuffer(GL_ARRAY_BUFFER,m_VBO);
    glBufferData(GL_ARRAY_BUFFER, sizeof(float)*VBO_content.size(), &VBO_content[0], GL_STATIC_DRAW);
    glBindBuffer(GL_ARRAY_BUFFER,0);

    ///Creation du VAO
        if(glIsVertexArray(m_VAO))
            glDeleteVertexArrays(1, &m_VAO);
        glGenVertexArrays(1, &m_VAO);


    ///REMPLISSAGE
    glBindVertexArray(m_VAO);




        glBindBuffer(GL_ARRAY_BUFFER, m_VBO);

        glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 8*sizeof(float), BUFFER_OFFSET(0));
        glEnableVertexAttribArray(0);

        glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, 8*sizeof(float), BUFFER_OFFSET(3*sizeof(float)));

        glEnableVertexAttribArray(2);

        glVertexAttribPointer(3, 3, GL_FLOAT, GL_FALSE, 8*sizeof(float), BUFFER_OFFSET(5*sizeof(float)));
        glEnableVertexAttribArray(3);



        glBindBuffer(GL_ARRAY_BUFFER, 0);
    glBindVertexArray(0);

And here is my rendering method for this object

glUseProgram(m_shader.getProgramID());


            glBindVertexArray(m_VAO);
            if(glGetError())
                std::cout << "Binding error : " << __FILE__ << " " << __LINE__  << std::endl;

           //Drawing, texture binding etc stuff that works fine, but is after the error

Any idea of what is doing this ? :slight_smile:

Have you checked if the error is perhaps already generated before the glBindVertexArray call? If not, is it possible that the rendering code runs (once) before the initialization code does and the value of m_VAO is uninitialized (i.e. essentially random) at that point?

Yes I dit, and there’s no error if I check before binding (just after UseProgram), so the problem comes from binding.
Uniinitalised VAO looked like a good solution, but I’m sure model is loaded before being rendered. (VAO is generated in constructor - which I guess isn’t really a good idea, should have made a separate method :stuck_out_tongue: - and cosntructor is called before main loop, so there’s no chance)
On the other side, if Problem is not about uninitalised VAO, I have no clue about why I get error only once.

EDIT : problem solved :slight_smile:
It was an issue due to use of legacy code by SFML library. (I used SFML texture wrapper and sf::Texture::bind. Now, I’ve written my own wrapper and I don’t get any error. This error came from sf::Texture initalisation)