GLMapBufferObj segfaults when glBufferData(,NULL,)

Hi,

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 );

CHECK_GL;

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 );

free(foo);

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?

Chris

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.

Mark

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.

Chris

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?

Chris