There's also an addictive quality to the pain we feel. I know it sounds weird, but you feel more alive sometimes when you're hurting, even though you know it's not good for you.
I have a mental "panic button" that I use to break out of my little spirals. Whenever I get close to the edge, I think of the line from Young Frankenstein where the young Doc is approaching the door to the family castle and says "Nice Knockers!" Almost always brings a smile to my face, even in the darkest moments.