Jump to content
  • Advertisement
Sign in to follow this  

SDL Segfault Crash since using SDL_net

This topic is 3484 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi all, I've got a very bizarre problem. I've been using SDL for input and graphics in my game for a little while with no problems. Recently I've just started using SDL_net for networking and ever since then the program crashes in a variety of 3rd party libraries (SDL itself, ftgl etc) with a segfault, usually on exiting the program, but occasionally while it is running. Does anyone have any tips for debugging this sort of thing? Whenever I try to see where it crashed it ends up crashing within some other library and not in my code, but it must be something that I have done as it worked before the networking. The networking appears to work as information is sent from one place to another without problems. Below is some code that receives information on the server in case there is something obviously wrong:
UDPpacket* p;
int clientid;

//Allocate memory for packets
p = SDLNet_AllocPacket(PACKET_SIZE);

//Grab all new packets and build them into messages
while(SDLNet_UDP_Recv(this->serversocket, p) == 1)
	//If we are here then we have received a packet
	clientid = this->GetClientID(p->address.host, p->address.port);

	if(clientid == -1)
		//We have a new client, create space for him
		clientid = this->CreateClient(p->address.host, p->address.port);
	if(clientid == -1)
		//Send a message back rejecting the poor person
		g_cLog.Write("CGameServer::Update() - No space for new clients to connect");

	//Load in the data
	CNetworkPacket*	np;
	np = new CNetworkPacket();
	memcpy(np, p->data, sizeof(CNetworkPacket) - sizeof(char*));
	np->data = new char[np->partdatasize];
	memcpy(np->data, &p->data[sizeof(CNetworkPacket) - sizeof(char*)], np->partdatasize);
	np->clientid = (char)clientid;


//Free up packet memory
p = NULL;

//Go through all clients and see if we have any complete messages for processing

Thanks in advance for any help. - James

Share this post

Link to post
Share on other sites
Thanks for the feedback, I've just worked out what the problem was. Finally one of the crashes led me to my packet sending function. I checked all my calculations of packet size (when I split large data sets into a number of smaller packets, to be reassembled on the other side) and they turned out to be calculating it incorrectly. I've fixed the sizing calculations and now it works.

My guess for why I was getting all the crazy output is that the packets are created using SDL memory allocation functions (which is probably allocated in the DLL's space?), so when I wrote data outside the memory that was allocated it messed up something else.

Thanks for the help.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!