I finally found the problem in my code.
I posted earlier that when I debug into my program it keeps crashing on a "new" operator but it runs fine. Now I found the cause of the problem. It is because I tried to access an object that was already deleted. It took me couple of days to find this problem. I don't know how you guys do it but I used _CrtCheckMemory to check the heap in all suspected areas. Right after I tried to access the deleted object, the program crashed in _CrtCheckMemory().

I still do not know why it runs fine and crashes when I debug it. Is the heap somehow different in the two cases?