I've been working on some new stuff, and have had a bit of a rough time as things were falling apart badly. So... when all else fails... Take a snooze!
I laid down for a while, envisioned the code in my head, and just rested.
A while later, I went back to the code, started walking through it, and lo and behold, I had the answer.
Anyone else ever do this? Step back. Chill. Meditate. Come back and solve a critical issue?