Can I use opengl to write texture after using cudaGraphicsGLRegisterImage

Now my code is like these:

while(condition){
    cudaGraphicsGLRegisterImage
    cudaGraphicsMapResources
    cudaGraphicsSubResourceGetMappedArray
    Do something
    cudaGraphicsUnmapResources
    cudaGraphicsUnregisterResource
    using OpenGL write texture
}

And now I find that cudaGraphicsGLRegisterImage has a high cost. And I will loop the process many times.
I don’t know what happen if I call the cudaGraphicsGLRegisterImage.
So I want to know if I can do like these:

cudaGraphicsGLRegisterImage
while(condition){
    cudaGraphicsMapResources
    cudaGraphicsSubResourceGetMappedArray
    Do something
    cudaGraphicsUnmapResources
    using OpenGL write texture
}
cudaGraphicsUnregisterResource

I use the code above, it looks like works well, I want to know if there is something wrong.