GLMapBufferObj segfaults when glBufferData(,NULL,)


I’ve encountered some strange behaviour trying to set up a OpenGL VBO for rendering of cuda output. The following code:

// ...

glGenBuffers(1, &m_vbo );

glBindBuffer( GL_ARRAY_BUFFER, m_vbo );

glBufferData( GL_ARRAY_BUFFER, sizeof(GLfloat)*256*256, NULL, GL_DYNAMIC_DRAW );

glBindBuffer( GL_ARRAY_BUFFER, 0 );


CUDA_SAFE_CALL( cudaGLRegisterBufferObject( m_vbo ) );

// ...

gives a segmentation fault at the call to RegisterBufferObject-call. After playing around with buffer type, usage type, etc. to no avail, I saw that the simpleGL-example in the SDK did the following

float* foo = (float*)malloc(sizeof(GLfloat)*256*256);

glBufferData( GL_ARRAY_BUFFER, sizeof(GLfloat)*256*256, foo, GL_DYNAMIC_DRAW );


thus actually defining the contents of the buffer to be something. And if I do this, my code works…

I guess since the code in the SDK does the extra malloc-gymnastics, maybe it is a known bug?


Hi Chris,

This is a known bug and we have a fix in progress. It was missed for the release notes – sorry for the inconvenience.

The workaround, is as you saw in the example, to allocate a dummy array to pass to glBufferData.


Hi Mark,

Thanks for your reply !

By the way, the cudaGLMapBufferObject definition in the 0.8 programming guide on p.34 lacks the “GL”-bit in the name and has different arguments than the definition in the header-file.


I discovered that if size is less than 65536 this works as expected.

glBufferData( GL_ARRAY_BUFFER, size, 0, GL_DYNAMIC_DRAW );

But once i tried with 65536 or more, I got a memory pointer far off from the usual value with

float4 *ptr = (float4*)glMapBuffer(GL_ARRAY_BUFFER, GL_READ_WRITE);


The same behaviour was observed with device emulation too.

Is the pointer illegal? (i.e., do you get a segfault if you try to use it?)

And if so, have you registered the buffer with CUDA, or is it plain GL?