"First off, you'd need advanced AI that doesn't have any bugs." For bugs to occur, your virtual world would have to be flawed. And since we're talking about technology beyond the singularity you can assume the accuracy and speed of said new technology will only increase. If so, then why say there will be bugs? Since computers will be programming the virtual world, cant you assume that it will be next to flawless? Even so, it would take the computer of that magnitude seconds to find problems in whatever code they program in, and fix it accordingly. Even if they don't, they're still increasing in processing speed, and their software is constantly updating. If there was a problem in code then it would be found relatively soon.
"There'd need to be a field of research in the programming department..." There wont be a need to do any sort of research on programming once we can develop AI that can execute commands based on what we ask.
"that right there won't be available for at least a few decades." Yes, this technology wont be available for a while. That's why I'm saying that this is happening beyond the singularity.
"what if the VR can stimulate your brain and allow you to feel?" Well, in this situation I'm assuming that your brain is already inside the computer. This means you're nothing more then a software program. The moment you're in the computer you can do anything you want with your mind, much more then just allowing you to feel things in the virtual world.
"when VR can do this, there will probably be a safety option to prevent pain, but what about hackers?" The only hackers you're going to be facing with are hackers that directly connect to your computer. If you're isolated in outer space, and certain precautions are taken to disable physical access to your computer, then real world hackers aren't an issue. Along with virtual world hackers, no one is going to be hacking you in your own computer. They'll have to develop the ability to comprehend what's happening in your computer and manipulate it. Remember, you wont be connected to anything in the outside world, including the internet, so hackers wont have any remote access to your computer. Also, If you're so scared of pain and hackers who might abuse it, then why not change your opinion about it once you're in the computer? You can get positive emotions from feeling pain if you really wanted to.
"And while you're in the game, how do you leave it?" Now, methods to leave the virtual world can be quite different. For one, you could know you're in a virtual world while you're in it. So you can decide at any moment when you want to leave. You could have some method that constantly reminds you every x minutes that you're in a virtual world. If you decide not to leave, your computer can delete the memory of it reminding you so you wont break immersion with the virtual world. You could have another thought process that is outside of the virtual world that decides for you to leave or not using your memory, but in this case what would be the point of leaving in the first place when you can create more thought processes and enter different virtual worlds using the same memory.
What if you cant leave the virtual world? Well, if that's the case, then that's the case. There is no moving around that. However you're not going to be trapped for all eternity. You still have all of your memory in your computer, which isn't attached to anything. So booting up a saved file of your conscious to host your memory is an option. But being trapped in a virtual world you're hosting isn't exactly the easiest thing. I don't see how you can be trapped in something that you have full control over.