Error mapping PBO cudaGraphicsResource

Hi everyone,

I have a problem with a CUDA buffer access : I register an OpenGL buffer to use it with CUDA, cudaGraphicsGLRegisterBuffer() return no error (i.e. cudasucess), but when I want to map my PBO with cudaGraphicsMapResources() I get “cudaErrorMapBufferObjectFailed”.

Here is my code (simplified but with the relevant parts) :

in the .h file

GLuint bufferID;
struct cudaGraphicsResource* PBO_CUDA_Widget;

in the .cpp file

void HDR_GLWidget::initializeGL()
{
	cutilSafeCall(cudaGLSetGLDevice(cutGetMaxGflopsDeviceId()));

        // create pixel buffer object
	glGenBuffersARB(1, &bufferID);
	glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, bufferID);
	glBufferDataARB(GL_PIXEL_UNPACK_BUFFER_ARB, width * height * 4, NULL, GL_STREAM_DRAW_ARB);
	glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, 0);
	
	cudaError_t error_test = cudaGraphicsGLRegisterBuffer(&PBO_CUDA_Widget, bufferID, cudaGraphicsMapFlagsWriteDiscard); //no cuda error here
}

void HDR_GLWidget::uploadBuffer
{
	cudaError_t error_test = cudaGraphicsMapResources(1, &PBO_CUDA_Widget, 0); //crash here

        [...]
}

Here is the error I get :
First-chance exception at 0x000007fefd47bccd in IHM_Qt_TM_cuda.exe: Microsoft C++ exception: cudaError_enum at memory location 0x073ff200…

I’m on a x64 machine with Windows 7, CUDA 4.2 on a GTX580.