SDL_NET problem

Started by
2 comments, last by hplus0603 16 years, 10 months ago
hello all. I am working on a game and i have a strange crash. in my game the client sends the host a msg after he presses the mouse. If I press it one time or two times or mybe even three everything is ok. But if I press it very fast (and i play the client side) the hosts program just crash and i have no idea why. Anyone has any idea why? P.s My program counts on that the first msg is a number and the next comes with _ And if its not that it might crash. Mybe thats it but i have no idea. (There is only 1 place in the whole game where it sends and get msgs. if its need to send anything it add it to the Vector themsgs and it waits until it get to that part of the game in order to send it.) (the function akel will make the game crash if its get wrong info) this is my host side:


   if (SDLNet_CheckSockets(sockkset, 2) > 0 ) 
                   {             
                      if (SDLNet_TCP_Recv(csd, infoo, 512))
                        {
                        fprintf( stderr, "Reacived %s ", infoo);
                          int haaag = int(atoi(infoo))    ;
                          int awqer2 = SDL_GetTicks();
                          for (int iag=0;iag<haaag;iag++)
                         {  
                            if (SDLNet_TCP_Recv(csd, infoo, 512))
                        {
                            akel(infoo); 
                            fprintf( stderr, "(inside Reacived %s )", infoo);
                            }
                     
                            
                             }         
                        
                       
                        
                        }
                        
                        }



this is my client side (only the stuff matters)

      int awqer = SDL_GetTicks();
                      
                      for (int kak=0;kak<countmsg;kak++)
                      {
                       while ((SDL_GetTicks()-awqer)<50)
            	      {
                      
                      }
                           
                           
                	len = strlen(themsgs[kak].sendingdata) + 1;
                if (SDLNet_TCP_Send(sd, (void *)themsgs[kak].sendingdata, len) < len)
	                {
                    wwhat=0;
                     mode=0;             
                    }   
                           awqer = SDL_GetTicks();
                      }


thanks in advance
Advertisement
Oh and I forgot...
This code is above the code that i posted for the client:

                    char bla[512];                                       sprintf(bla, "%d", countmsg);                  	len = strlen(bla) + 1;                if (SDLNet_TCP_Send(sd, (void *)bla, len) < len)	                {                    wwhat=0;                     mode=0;                                 }   
First of all, your variable names terrify me. :-P

Second, my instincts say that you're having a buffer overflow somewhere. It's probably not the sprintf(), but it could be someday; use snprintf() instead.

I'm suspicious about "themsgs". I dunno if it's an array or a C++ vector, or how big it is... but an overflow there seems like the obvious thing. If I recall right, the C++ vector's [] operator is not bounds-checked.

Is it your client or server program that's crashing, anyway?

[Edited by - Icefox on June 7, 2007 11:54:10 AM]
-----http://alopex.liLet's Program: http://youtube.com/user/icefox192
When your program crashes, look in the debugger at the stack trace. Follow it back up to the line in your program where it's crashing. That will give you a clue as to what's going wrong.
enum Bool { True, False, FileNotFound };

This topic is closed to new replies.

Advertisement