Recipe for debugging:
- Think about the error.
- Think about what you are doing.
- Suppress the things that you suspect are causing the error. Check the result again.
- Force an error so that your suspicion is confirmed or denied.
- Throw some salt over your left shoulder.
- Look hard at the source files. Let the bug stand out. If needed, keep staring for hours at your screen, waiting for the bug to manifest itself.