I can't figure out where is the faulty argument and I can't find any pointer returning NULL undesirably.
If you cannot figure out which line of your code causes the error place a beep in the middle of the function and run your game. Do you hear the beep before you see the error message? If so, move the beep further down until, otherwise move it up. This way you can exactly determine which line is causing the trouble.