Sign in to follow this  
Yhonatan

SDL_NET problem

Recommended Posts

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

Share this post


Link to post
Share on other sites
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;
}


Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this