Getting an error code 999 everytime I try to use OpenGL with CUDA

I have a laptop with CUDA toolkit 11.6 with RTX 3070 MAX-Q in it. When I try to run any program which uses OpenGL context , I get an error like this :
The OS in it is ENDEAVOUR OS. Everything I need is installed already .

[rishabhj@rishabh-nitroan51545 cuda-samples-11.6]$ ./GL
simpleGL (VBO) starting...

GPU Device 0: "Ampere" with compute capability 8.6

CUDA error at ./ code=999(cudaErrorUnknown) "cudaGraphicsGLRegisterBuffer(vbo_res, *vbo, vbo_res_flags)" 
CUDA error at ./ code=400(cudaErrorInvalidResourceHandle) "cudaGraphicsUnregisterResource(vbo_res)"

This example was taken from the CUDA-Samples provided on the GitHub Repo. The original code is preety long , so I don’t want to post it here . IMO, this is a big problem because, ARRAYFIRE and other libraries which use OpenGL are not working too !

I guess you’re in offload mode, try running it with prime-run or switch to the nvidia as primary gpu.

Thank you so much! I really appreciate your help :-)