Hey everyone, this one's got me baffled. I had a bit of code that I kept on using over and over in the same program, so I figured it would be simpler and easier just to make it a function:
For some reason, when I replaced the exact same lines of code with a call to the function, I would always get a stack overflow. Then I made the function inline, and it worked fine again. Is there any quick and obvious reason that I'm not seeing, or is it something very code-specific?
void backToConnect(HWND dialogToEnd);
server = new Socket;
dlgState = DS_CONNECT;
Hmm, never mind... now, it doesn't work with the inline either. Still, any ideas? I thought the code should function in the same way since server and dlgState are global variables, but apparently it doesn't...
Maybe you have to pass a pointer to server...
server->release(); // It doesn't look like server is a global variable.
Can you have a global object???
But I dunno... I would have thought if was something like that, you'd have gotten a compile error (?)
Hmm... well, I have at the top of my code, before my WinMain():
And everything else (if I coded everything like I thought I did) accesses server as a global variable. Besides, why would it cause a stack overflow? Or did I totally get what you're saying wrong...
The first server is created like so:
server = new Socket; //At the top of WinMain()
And also, should I be ignoring the "stack overflow"? I thought that usually means infinite recursion or something, but I don't see why changing existing line-by-line code into a function call should cause infinite recursion when the original code didn't.
Oh, forgot to mention, but at this point it IS supposed to delete the old socket and create a new one, since this gets called when the server has disconnected from the client and the client gets the 0-byte or SOCKET_ERROR recv.
Well, I hit debug when it crashed, and popped up the "call stack" window, and here is my analysis:
Also, once in a while it will simply not crash but infinitely pop up messageboxes that say "Connection to server lost" (which SOUNDS like infinite recursion to me), after which right-clicking "My Computer" and going to properties results in a message saying "Access to the specified device, path, or file is denied", and Notepad has "not enough memory" to run while MSVC++ does... Any ideas? :confused:
MessageBox(hWnd, "Connection to server lost.", "Error", MB_OK);
server->hasData() which calls:
Heh, well, any ideas as to the cause? Or do you need more code or something, or just lost interest? :p
Just a couple of thoughts..
Are you sure your backToConnect() function actually ends? Maybe put some additional debugging in at the start and end of the function to prove that it is.
Does it release the socket correctly here:
HI nothing happened with ur code except this that ur program crashes the whole pc system so..........
it isssss sugeested that. ........ u r doin good job continue it:rolleyes:
I haven't gotten time yet, but I'll be sure to read up on those articles.
Thanks for the suggestion, I'll try that in a little while, but for the moment I've switched back to my old line-by-line code and am just about to finish my overall project, and I don't feel like stopping to debug that part at this moment. I'll let you know what I find when I do try it, though. Also, release() SHOULD properly release the socket, and I've never had a problem with it before (**Well, I did but I fixed it right away).
Thank you, I think I will take your advice and finish my program.
Ahh... Hammer, I tried what you suggested and I logged the start and end of the function, but it never showed up. I also got my program to log every call of LoginProc(), and under LoginProc(), every time serverShutdown() returns true. I got 535 LoginProc() calls and serverShutdown() returned true 484 times, but in between, no backToConnect() start or end. Should I start searching for my compiler install CD?
Salem, I read the first article, but I don't really get the point. Are you saying to check for garbage 0xCDCDCDCD and 0xDDDDDDDD values, or are you trying to suggest that I use the various ASSERT_'s, or that I use static_cast, or that I use DYNAMIC_DOWNCAST, or that I should use ON_NOTIFY_REFLECT_EX instead of ON_NOTIFY_REFLECT, and return TRUE from my handler? :confused: