glMapBuffers giving problems


I am trying to do Physics (time integration and collision detection) on CUDA. Since I have based my program on SimpleGL example from the SDK I use VBOs.

After running my physics kernel I draw from the desired VBO and the results are fine but I want to map this buffer into client memory to use as a normal vertex array so I use glMapBuffer. But this is giving me errors at run time.

Specifically I do the following in the display loop:

   // run CUDA kernels to generate vertex positions

    runCuda(vboFloor); // generate vertex positions for floor(kernel from the simpleGL example)

    cudaIntegrator(vboNewPosA,dt);//My physics Kernel


   // set view matrix



    glTranslatef(0.0, 0.0, translate_z);

    glRotatef(rotate_x, 1.0, 0.0, 0.0);

    glRotatef(rotate_y, 0.0, 1.0, 0.0);

   // render from the floor vbo

    glBindBuffer(GL_ARRAY_BUFFER, vboFloor);

    glVertexPointer(4, GL_FLOAT, 0, 0);


  glColor3f(0.0, 0.0, 0.0);


  glDrawArrays(GL_POINTS, 0, mesh_width * mesh_height);


	glBindBuffer(GL_ARRAY_BUFFER, 0);


// this snippet works

#if 0

	// render new positions

	glBindBuffer(GL_ARRAY_BUFFER, vboNewPosA);

	glVertexPointer(4, GL_FLOAT, 0, 0);


  glColor3f(1.0, 0.0, 0.0);


  glDrawArrays(GL_POINTS, 0,  GRIDX * GRIDY);


	glBindBuffer(GL_ARRAY_BUFFER, 0);


   glBindBuffer(GL_ARRAY_BUFFER, vboNewPosA);

    float *data = (float *) glMapBuffer(GL_ARRAY_BUFFER, GL_READ_WRITE);


    if(data != NULL)




I create the VBOs in the same manner they are done in SimpleGL example.

I do cudaGlMapBuffer and cudaGLUnmapBuffer in the kernels and want to use them as pure and simple GL vertex arrays.

Any pointers ?