0
\$\begingroup\$

This is the "init" code of the Renderer class:

glGenBuffers(1,&_idVBO);
glGenBuffers(1,&_idEBO);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,_idEBO);
glBindBuffer(GL_VERTEX_ARRAY,_idVBO);

GLint lUV       = glGetAttribLocation(_SID,"inUV");
GLint lPosition = glGetAttribLocation(_SID,"inPosition");

glEnableVertexAttribArray(lPosition);
glEnableVertexAttribArray(lUV);
glVertexAttribPointer(lUV, 3, GL_FLOAT, GL_FALSE, 5 * sizeof(GLfloat), (GLvoid*)0);
glVertexAttribPointer(lPosition, 2, GL_FLOAT, GL_FALSE, 5 * sizeof(GLfloat), (GLvoid*)(3*sizeof(GLfloat)));

...and this is the "flush" function:

glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,_idEBO);
glBindBuffer(GL_VERTEX_ARRAY,_idVBO);
glBufferData(GL_ARRAY_BUFFER,_lVBO*sizeof(GLfloat),_pOriginVBO,GL_STATIC_DRAW);
glBufferData(GL_ELEMENT_ARRAY_BUFFER,_lEBO*sizeof(GLuint),_pOriginEBO,GL_STATIC_DRAW);

glDrawElements(GL_TRIANGLES,6,GL_UNSIGNED_INT,0);

The glDrawElements call crashes with error code c0000005, which is caused by memory acces violation i.e. bad pointers. But I do not understand where the problem is. Any ideas? Thanks in advance...

\$\endgroup\$
1
  • \$\begingroup\$ Can you include initialization code for your buffers? \$\endgroup\$
    – wondra
    Nov 25, 2015 at 18:57

1 Answer 1

2
\$\begingroup\$

One (or more) of your gl calls previous to glDrawElements is not being passed correct information. So when you finally get to glDrawElements it crashes on you because that information is not set properly. Here is what I do to debug that issue:

After each gl call place a ChecKGLError(); Here is that function:

void _CheckGLError(const char* file, int line);

#define CheckGLError() _CheckGLError(__FILE__, __LINE__)

void _CheckGLError(const char* file, int line)
{
    GLenum err ( glGetError() );

    while ( err != GL_NO_ERROR )
    {
        std::string error;
        switch ( err )
        {
            case GL_INVALID_OPERATION:  error="INVALID_OPERATION";      break;
            case GL_INVALID_ENUM:       error="INVALID_ENUM";           break;
            case GL_INVALID_VALUE:      error="INVALID_VALUE";          break;
            case GL_OUT_OF_MEMORY:      error="OUT_OF_MEMORY";          break;
            case GL_INVALID_FRAMEBUFFER_OPERATION:  error="INVALID_FRAMEBUFFER_OPERATION";  break;
        }
        std::cout << "GL_" << error.c_str() <<" - " << file << ":" << line << std::endl;
        err = glGetError();
    }

    return;
}
\$\endgroup\$
2
  • \$\begingroup\$ I get "Invalid Enum" on line 44, which is: glBindBuffer(GL_VERTEX_ARRAY,_idVBO); \$\endgroup\$
    – Dan
    Nov 25, 2015 at 21:15
  • \$\begingroup\$ glBindBuffer should have: GL_ARRAY_BUFFER as an enum. \$\endgroup\$
    – mythos
    Nov 25, 2015 at 21:21

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .