cudaGraphicsMapResources(...) fails in sharedlibrary implementation of cuda sample

Hi!

I'm trying to mod a few cuda sample programs to learn the concepts.  In my current test, I'm trying to mod the fluidsGL example into a shared library (.so) that's loaded in as a plugin by another application.
  1. The plugin launches it’s own window, using the glutCreateWindow(…) call.
  2. Subsequently focus on the window is lost to the host application. I presume this means the OpenGL context is no longer current.
  3. Focus is brought back by using the glutSetWindow(…) call.
  4. The advectParticles(…) kernel launch function fails on cudaGraphicsMapResources(…) call. The reported error is invalid OpenGL context, and the application crashes.

I haven’t been able to find any documentation on cudaGraphicsMapResources(…) in depth enough to figure out what information it actually needs. Does anyone have any ideas what may be causing this function to fail? and how I might fix it?

Thanks!