CUDA GL Interoperability - existing opengl context

I am trying to integrate CUDA with an application that maintains its own opengl render window (using wxwidgets gl canvas). Simply put, the behavior I’m seeing is when I first set the device using:


Calls to cudaMalloc() and cudaGLRegisterBufferObject() result in the MSVS error:

First-chance exception … cudaError_enum at memory location 0x…

Curiously, when I set the device using:


Calls to cudaMalloc() appear to succeed, but calls to cudaGLRegisterBufferObject() still fail with the same error as above.

I am able to successfully run code that does NOT use any cudaGL calls, but I have not been able to run anything using cudaGL buffer objects unless I follow what was done in the example projects and call glutInit() and glewInit() after CUT_DEVICE_INIT(). Is there a problem with using CUDA after the GL context has already been created elsewhere?

Thanks for any ideas!

I have code using CUDA and OpenGL interoperability in a wxGLCanvas. My code doesn’t call either cudaGLSetGLDevice or cudaSetDevice though. The relevant code is here:…vis_wx/main.cpp…