Couple of thoughts...
One is that when you work for a long period on something you get sort of code-blind and go past the threshold of diminishing returns. You aren't really seeing what you're looking at any more, you're seeing what you think should be there. It will take you many hours to do a real hour's worth of work. When you come back fresh later on, you often pick up the problem very quickly.
Another related thing is "rubber duck debugging", where the act of describing the problem to someone else makes you clarify the situation in your own head... so you suddenly realise what you're doing wrong. The other person didn't do anything except sit and listen. The theory goes that you can explain things to a rubber duck (some say a teddy bear) sitting on your desk; get the same result without bothering someone.
A simple, quick solution can simply be to go for a walk (10-15 minutes). Get away from your desk, get some air, stretch your legs, let your attention wander on to other things. When you come back you often solve things pretty fast.
Plus I also recommend having a sort of standard mental script to check the basics.