Ridiculous sendto Debug Crash

Started by
2 comments, last by blaze02 17 years, 6 months ago
My prog works fine, but if I run it in debug, it crashes in the destructor of my networking class. I'm a little confused as to how this is happening. The problem only occurs in debug mode. If I comment out just the sendto call, the crash does not occur. When the crash occurs, it happens in the closesocket call. I've put breakpoints on the call and the params are good. I send a 512 byte msg which I ZeroMemory, then call sprintf_s to input a text string. It actually crashes if I call closesocket right after my sendto call. Has anybody ever had a problem in debug mode with network code? Any ideas? On a side note: I did not know that sprintf_s sets the entire buffer to -3. I.e. I call sprintf_s with a zeroed 512 byte buffer. The buffer ends up being the string I wrote to it, the null terminator, and the rest of the zeroes end up getting set to -3. At least that is what happens in debug mode. I assumed sprintf_s would not destroy my entire buffer :(
-------Harmotion - Free 1v1 top-down shooter!Double Jump StudiosBlog
Advertisement
bump :)

So a little more info. This crash only occurs in debug mode... And by debug mode, I mean running the program with F5 (not Ctrl-F5) either in Release or Debug builds. The return value of closesocket is fine. Though, it only returns from the function when running with Ctrl-F5. The WSAGetLastError func returns 0.

Any suggestions? I'll try to recreate the problem in a simpler project.
-------Harmotion - Free 1v1 top-down shooter!Double Jump StudiosBlog
The Windows runtime does extra things to "help out" when running from the debugger. This includes clearing out newly allocated memory with some sentinel value.

When you say "crashes" that's kind of hard to figure out -- are you getting a c0000005 access violation error? Or some other crash? Is it hitting a breakpoint, or a heap validation check?

Also, without seeing code, I don't think anyone can give you more help than this.
enum Bool { True, False, FileNotFound };
I'm running VS2005. This happens when I run my prog with "Start Debugging" (just hitting F5, whether it be in debug or release mode). It basically hits a breakpoint/assertion in the networking dll (ws2_32.dll i think). It breaks me out to my compiler, stops code execution at the line of the closesocket call, and pops up this warning:
Quote:
Windows has triggered a breakpoint in MyProgram.exe.

This may be due to a corruption of the heap, and indicates a bug in MyProgram.exe or any of the DLLs it has loaded.

The output window may have more diagnostic information


And the output window does not have any more info.
The compiler tells me the error is many many call frames deep inside the winsock dll.
But like you said, I don't see any way for someone to help me unless this has happened to them before. I'll try to recreate it in a smaller project.
-------Harmotion - Free 1v1 top-down shooter!Double Jump StudiosBlog

This topic is closed to new replies.

Advertisement