Way back at the dawn of time, there was a regular issue with low quality applications that would run XGrabKeyboard() (or XGrabPointer()), and then get stuck without releasing it again. If you can, try to log in over the network from another machine and kill application processes one by one until it releases? It’s most likely the video game (or library used by it) that has gotten stuck.
I’m not sure, there can always be other issues. But note that closing the window is not the same as terminating the application. When you close the window, the application gets a signal that it usually handles as cleaning up and shutting down. But if it is hanging, that task is not performed and resources are still held.