Sign in to follow this  
sajis997

Application crashes at glDrawArrays(....)

Recommended Posts

Hello forum,

The application that I am trying to develop is crashing at the point glDrawArrays(....) . The snippet is as follows:


void Hilbert2DScene::render()

{

if(!mInitialized)

return;

/*

* Bind the vertex array object and vertex buffer object

* */

glBindVertexArray(mVaoID);

/*

* Now bind it to the context using the GL_ARRAY_BUFFER binding point

* */

glBindBuffer(GL_ARRAY_BUFFER,mVboVerticesID);

 

mShader->Use();

 

GL_CHECK_ERRORS;

 

//allocate the buffer if the buffer is not allocated yet

if(!mIsBufferAllocated)

{

//ALLOCATE THE BUFFER HERE

unityCube(mIteration,mDim);

 

//specify the amount of storage we want to use for the buffer

glBufferData(GL_ARRAY_BUFFER,sizeof(glm::vec3) * mVertices.size(),&mVertices[0],GL_STATIC_DRAW);

 

mIsBufferAllocated = true;

 

mShowPoints = getNumberOfPointsForIteration(mIteration,mDim);

}

 

if(mClearBackground)

glClearColor( 0.0f, 0.0f, 0.0f, 1.0f );

 

static const GLfloat color[] = {0.0f,0.0f,0.0f,1.0f};

static const GLfloat depth = 1.0f;

 

glClearBufferfv(GL_COLOR,0,color);

glClearBufferfv(GL_DEPTH,0,&depth);

 

 

//draw stuff

 

//transfer the scene along the z-axis

glm::mat4 T = glm::translate(glm::mat4(1.0f),glm::vec3(0.0f,0.0f,mDist));

 

//the rotation matrix along X concatenated with the translation matrix

glm::mat4 Rx = glm::rotate(T, glm::radians(static_cast<float>(mRX)),glm::vec3(1.0f,0.0f,0.0f));

 

//rotation matrix along Y is concatenated with the rotation matrix along X

glm::mat4 MV = glm::rotate(Rx,glm::radians(static_cast<float>(mRY)),glm::vec3(0.0f,1.0f,0.0f));

 

mModelViewMatrix = mProjectionMatrix * MV;

 

glEnableVertexAttribArray((GLuint)0);

 

 

glUniformMatrix4fv(mShader->getUniform("MVP"),1,GL_FALSE,glm::value_ptr(mModelViewMatrix));

 

if(mShowPoints < getNumberOfPointsForIteration(mIteration,mDim))

++mShowPoints;

 

glDrawArrays(GL_LINE_STRIP,0,mShowPoints);

 

 

glDisableVertexAttribArray(0);

glBindVertexArray(0);

 

GL_CHECK_ERRORS;

 

mShader->UnUse();

}      

 

I tried with gdb debugger and the backtrace leaves with nothing other than "??" . I am not sure where to start with . Some hint from the forum is eagerly awaited ..


Thanks

Share this post


Link to post
Share on other sites

Hi

 

I checked both the values - the size of the vector mVertices and the value of the mShowPoints and they are the same. Now I am attaching more code snippet that may help you to help to connect the dots and debug the issue:

 

void Hilbert2DScene::render()
{
    if(!mInitialized)
        return;
    /*
     * Bind the vertex array object and vertex buffer object
     * */
    glBindVertexArray(mVaoID);
    /*
     * Now bind it to the context using the GL_ARRAY_BUFFER binding point
     * */
    glBindBuffer(GL_ARRAY_BUFFER,mVboVerticesID);

    mShader->Use();

    GL_CHECK_ERRORS;

    //allocate the buffer if the buffer is not allocated yet
    if(!mIsBufferAllocated)
    {
        //ALLOCATE THE BUFFER HERE
        unityCube(mIteration,mDim);

        //specify the amount of storage we want to use for the buffer
        glBufferData(GL_ARRAY_BUFFER,sizeof(glm::vec3) * mVertices.size(),&mVertices[0],GL_STATIC_DRAW);

        mIsBufferAllocated = true;

        mShowPoints = getNumberOfPointsForIteration(mIteration,mDim);
    }

    if(mClearBackground)
        glClearColor( 0.0f, 0.0f, 0.0f, 1.0f );

    static const GLfloat color[] = {0.0f,0.0f,0.0f,1.0f};
    static const GLfloat depth = 1.0f;

    glClearBufferfv(GL_COLOR,0,color);
    glClearBufferfv(GL_DEPTH,0,&depth);


    //draw stuff

    //transfer the scene along the z-axis
    glm::mat4 T = glm::translate(glm::mat4(1.0f),glm::vec3(0.0f,0.0f,mDist));

    //the rotation matrix along X concatenated with the translation matrix
    glm::mat4 Rx = glm::rotate(T, glm::radians(static_cast<float>(mRX)),glm::vec3(1.0f,0.0f,0.0f));

    //rotation matrix along Y is concatenated with the rotation matrix along X
    glm::mat4 MV = glm::rotate(Rx,glm::radians(static_cast<float>(mRY)),glm::vec3(0.0f,1.0f,0.0f));

    mModelViewMatrix = mProjectionMatrix * MV;

    glEnableVertexAttribArray((GLuint)0);


    glUniformMatrix4fv(mShader->getUniform("MVP"),1,GL_FALSE,glm::value_ptr(mModelViewMatrix));

    if(mShowPoints < getNumberOfPointsForIteration(mIteration,mDim))
        ++mShowPoints;

    glDrawArrays(GL_LINE_STRIP,0,mShowPoints);

    glBindBuffer(GL_ARRAY_BUFFER,0);

    glDisableVertexAttribArray(0);
    glBindVertexArray(0);

    GL_CHECK_ERRORS;

    mShader->UnUse();
}
 
 
void Hilbert2DScene::initialise()
{
    if(mInitialized)
        return;

    if(!initializeOpenGLFunctions())
    {
        std::cerr << "Modern OpenGL Functions could not be initialized" << std::endl;
        std::exit(EXIT_FAILURE);
    }

    GL_CHECK_ERRORS;

    //sets the polygon rasterization mode
    glPolygonMode(GL_FRONT_AND_BACK,GL_LINE);

    //load the shaders
    loadShaders();

    GL_CHECK_ERRORS;

    /*
     * Vertex array object represent the vertex fetch stage of the OpenGL pipeline
     * and used to supply the input to the vertex shader
     * */
    glGenVertexArrays(1,&mVaoID);
    /*
     * generate the name of the buffer
     * */
    glGenBuffers(1,&mVboVerticesID);

    /*
     * Tell OpenGL where in the buffer object the data is
     * 1st - index to the vertex attribute
     * 2nd - the number of components that are stored in the buffer for each vertex
     * 3rd - the type of the data
     * 4th - tell if the data in the OpenGL buffer should be normalized or not before being passed to the vertex shader
     * 5th -
     * */
    glVertexAttribPointer((GLuint)0,3,GL_FLOAT,GL_FALSE,0,0);

    //make the initialization flag to true
    mInitialized = true;
}
 
void Hilbert2DScene::paint()
{
    if(!mInitialized)
        initialise();

    resize(mWidth,mHeight);

    render();
}
 

 

The code structure is coupled with the qt5 interface and I can confirm you that I am not using any qtopengl wrapper classes, all raw modern opengl commands are used, qt5 is here for the UI and nothing else. The paint() function called above is basically invoked from the signal and slot mechanism in Qt. You could safely ignore it though.

 

connect(win,SIGNAL(beforeRendering()),mHilbert2DScene,SLOT(paint()),Qt::DirectConnection);

 

 

Let me know if there is more information I can provide you with to address this issue.

 

Thanks

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