Jump to content
  • Advertisement
Sign in to follow this  
_Flame_

OpenGL glBindVertexBuffer and INVALID_OPERATION(0x502)

Recommended Posts

Posted (edited)

Hello.
From documentation: 

Quote

GL_INVALID_OPERATION is generated by glBindVertexBuffer if no vertex array object is bound.

But I bind VAO before calling glBindVertexBuffer.

Initialization:

    glGenVertexArrays(1, &m_VAO);

    glBindVertexArray(m_VAO);
    glVertexAttribFormat(0, 3, GL_FLOAT, false, offsetof(vertex, coords)); 
    glVertexAttribBinding(0, 0);
    glEnableVertexAttribArray(0);

    glVertexAttribFormat(1, 3, GL_FLOAT, false, offsetof(vertex, color)); 
    glVertexAttribBinding(1, 0);
    glEnableVertexAttribArray(1);

    glVertexAttribFormat(2, 2, GL_FLOAT, false, offsetof(vertex, tex_coords)); 
    glVertexAttribBinding(2, 0);
    glEnableVertexAttribArray(2);

    glVertexAttribFormat(3, 3, GL_FLOAT, false, offsetof(vertex, normal_coords)); 
    glVertexAttribBinding(3, 0);
    glEnableVertexAttribArray(3);

    glBindVertexArray(0);

    glGenBuffers(1, &m_VBO);
    glGenBuffers(1, &m_EBO);

    glBindBuffer(GL_ARRAY_BUFFER, m_VBO);
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_EBO);

    glBufferData(GL_ARRAY_BUFFER, vertices.size() * sizeof(vertex), vertices.data(), GL_STATIC_DRAW);
    glBufferData(GL_ELEMENT_ARRAY_BUFFER, indices.size() * sizeof(unsigned), indices.data(), GL_STATIC_DRAW);

    glBindBuffer(GL_ARRAY_BUFFER, 0);
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);

rendering:

    glBindVertexArray(m_VAO);
    glBindVertexBuffer(0, m_VBO, 0, sizeof(vertex));
    int error = glGetError(); // INVALID_OPERATION(0x502)

    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_EBO);
    glDrawElements(GL_TRIANGLES, m_indexCount, GL_UNSIGNED_INT, 0); //crash

 

Edited by _Flame_

Share this post


Link to post
Share on other sites
Advertisement

Remember, OpenGL errors are sticky - that GL_INVALID_OPERATION may not be from you calling glBindVertexBuffer.

From the glGetError documentation:

glGetError returns the value of the error flag. Each detectable error is assigned a numeric code and symbolic name. When an error occurs, the error flag is set to the appropriate error code value. No other errors are recorded until glGetError is called, the error code is returned, and the flag is reset to GL_NO_ERROR. If a call to glGetError returns GL_NO_ERROR, there has been no detectable error since the last call to glGetError, or since the GL was initialized.

Check the the value returned by glGetError immediately before you call glBindVertexBuffer. You might need to sprinkle calls to glGetError about your code to identify which function is generating the error.

Share this post


Link to post
Share on other sites
Posted (edited)
24 minutes ago, dave j said:

Remember, OpenGL errors are sticky - that GL_INVALID_OPERATION may not be from you calling glBindVertexBuffer.

From the glGetError documentation:

 

Check the the value returned by glGetError immediately before you call glBindVertexBuffer. You might need to sprinkle calls to glGetError about your code to identify which function is generating the error.

You are right but glGetError before glBindVertexBuffer returns 0.

But what is interesting that glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_EBO); also returns GL_INVALID_OPERATION.

Edited by _Flame_

Share this post


Link to post
Share on other sites

I found the root cause. Rookie mistake.

I kept my mesh in std::vector and buffers were destroyed during copy/assignment process. :)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!