Basically I have two problems. I'm currently developing a networked pong game using SDL and C with my class at college. It has the functionality to support up to 16 players in a single game, but issues are arising which causes the program to crash at random times and some images get messed up when new players join.
Okay first the program crashes randomly after like 5 minutes to 1 hour when SDL_UpperBlit is called like so:
Code:
#define MAX_BLITS 34
struct blit {
SDL_Surface *src;
SDL_Rect *srcrect;
SDL_Rect *dstrect;
} blits[MAX_BLITS];
void update_screen(void)
{
int i;
for (i = 0; i < numupdates; ++i) {
if (blits[i].src == 0 || blits[i].srcrect == 0 ||
screen == 0 || blits[i].dstrect == 0) {
continue;
}
SDL_UpperBlit(blits[i].src, blits[i].srcrect, screen,
blits[i].dstrect);
}
SDL_UpdateRects(screen, numupdates, dstupdate);
numupdates = 0;
}
The design of the program is that each client loads a ball image, two white paddles (horizontal and vertical) and one red paddle they control (horizontal or vertical). The server assigns players a side based on the order they join. Each player sends its paddle to the server. The server sends all paddles out to the players and they assign the appropriate image to draw based on the index in an array like so:
Code:
if (ball.alive) {
for (j = 0; j < players; j++) {
if (j != get_client_pos()) {
p = get_paddle(j);
if (j == 0 || j == 1 || j == 4
|| j == 5 || j == 8 || j == 9
|| j == 12 || j == 13)
p.image = *other_vert;
else
p.image = *other_horz;
if (p.alive)
draw_object(&p);
tmp[j] = p;
}
}
send_paddle(player, server_ip);
draw_object(&player);
draw_object(&ball);
}
The problem is when a third person joins the vertical white paddle on player one and player two's opposite side shrinks in height to the point where it is as small as the ball. And the third person sees all paddles fine.
Anyways any suggestions towards either problem would help greatly.