How can I prevent hanging sliding doors from coming off track?
Tip #1 
I do a lot of remodels and the easiest way to make a bedroom look newer is take out the old hollow doors or mirrored doors and put in 6 panels.  Not many closets are square either.  The first thing you need to do is use the rolling mechanism to adjust the door meet the wall as good as you can.  You can angle the rollers and move them up and down.  Obviously your door needs to slide on the floor so you have to play with this a little.  But try to get each door to match its outside wall.

Tip #2
Buy better rollers.  These only cost a couple dollars at big box and if you are taking old ones out, there is no extra work.  For instance the roller in Mazura's answer isn't as adjustable as the normal roller you would get at big box.

Tip #3
You want a little friction on the flooring... But that only works with carpet.  If closet doors are flung open the pressure of the roller will eventually affect the track each time it jumps off.  So get the doors a little lower.

Tip #4
Make sure the rollers are about 3-4 inches from the outside of each door.  The closer to the middle your rollers are, the easier for them to jump.

Tip #5
Get a good light/flashlight and inspect your tracks.  Most tracks are about the same quality (I am sure there are high end ones but I haven't seen them).  You can have two problems with the track.  First the track can be angled down.  This just happens with the weight of the door over time.  It actually doesn't hurt to have it angled up slightly (open side of track).   For this use a wood block and hammer.  

The other thing that goes wrong is the lip itself becomes deformed or it get pushed down.  I would simply tap this into place with a hammer.  For more deformed sections I break out the pliers.  If I am having an issue I go through the whole track with pliers.  

Tip #6
Grease the wheels and track.