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?