winsock heap problem
hi all.
working with winsock for LAN multiplayer.
everything works just fine until i shut down the sockets and re-create them. the compiler gives me a corrupted heap error.
i think i've narrowed it down the the call to recvfrom() when our listen thread
is starting, but don't really understand why this affects the problem.
thanks
-programmer_tom
This usually indicates buffer overrun. Somewhere in your code, you're likely writing beyond your allocated memory. In recvfrom, the buffer and buffer length parameters would be good source of this.
Other than that, it could be any dangling pointer, unallocated pointer, or other usual suspects for memory corruption.
Other than that, it could be any dangling pointer, unallocated pointer, or other usual suspects for memory corruption.
char szBuffer[MAX_MSG_LEN] = "\0"; SOCKADDR_IN saInClient; int nAddrSize = sizeof saInClient; int nRet = recvfrom ( m_socket, // Bound socket szBuffer, // Receive buffer MAX_MSG_LEN, // Size of buffer in bytes 0, // Flags (sockaddr*) &saInClient, // Buffer to receive client address &nAddrSize ); // Length of client address buffer
You know you can edit your posts?
There's no reference anywhere there to the heap - no STL containers, and nothing using malloc / new, so that isn't where your problem is.
There's no reference anywhere there to the heap - no STL containers, and nothing using malloc / new, so that isn't where your problem is.
What Steve said, edit and delete your first two posts with the code in it.
Also what Steve said, that is not where your problem is, besides some interesting programming habits...
Also what Steve said, that is not where your problem is, besides some interesting programming habits...
Its hard to say without seeing more of your code (esp the part 'shut down the sockets and re-create them').
I would test every return code from every one of the socket lib functions to make sure they are doing the right things the second time thru.
I would test every return code from every one of the socket lib functions to make sure they are doing the right things the second time thru.
thx guys. i didn't know you could edit your posts. i also realize nothing is being put on the heap there, which makes it tougher to debug. i went through once and tested the return codes from all the winsock calls and they all come back ok. i'll go through it again.
the reason i'm creating and destroying the objects is i wanted to create a network browsing screen for our game that shows other games on the lan. when you select join or host, the client/server setup may change so i thought why not just close it down, and reopen it under different slient/server setup (rather than changing around the properties of the in/out sockets).
nothing i've see in the documentation says you cannot do this.
is it illegal to call WSAStartup and WSACleanup more than once during execution?
the reason i'm creating and destroying the objects is i wanted to create a network browsing screen for our game that shows other games on the lan. when you select join or host, the client/server setup may change so i thought why not just close it down, and reopen it under different slient/server setup (rather than changing around the properties of the in/out sockets).
nothing i've see in the documentation says you cannot do this.
is it illegal to call WSAStartup and WSACleanup more than once during execution?
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement