From aad984176b4afc7ae08dcdceb50e41cf3fc96e55 Mon Sep 17 00:00:00 2001 From: stpohle Date: Sat, 7 Jun 2003 19:05:55 +0000 Subject: [PATCH] Bugfixing the current crash problem... but still no cloe where it comes from --- src/bomberclone.h | 3 +- src/debug.c | 9 ++++ src/field.c | 11 +++-- src/packets.c | 1 + src/player.c | 122 ++++++++++++++++++++++++++-------------------- 5 files changed, 89 insertions(+), 57 deletions(-) diff --git a/src/bomberclone.h b/src/bomberclone.h index ed392f3..9bb3dec 100644 --- a/src/bomberclone.h +++ b/src/bomberclone.h @@ -1,4 +1,4 @@ -/* $Id: bomberclone.h,v 1.37 2003/06/06 23:22:03 stpohle Exp $ */ +/* $Id: bomberclone.h,v 1.38 2003/06/07 19:05:55 stpohle Exp $ */ /* bomberclone.h */ #ifndef _BOMBERCLONE_H_ @@ -259,6 +259,7 @@ extern void d_playerdetail (char *head); extern void d_gamedetail (char *head); extern void d_printf (char *fmt,...); extern void d_bitprint (int bits, int nr); +extern void d_fatal (char *fmt,...); // single.c diff --git a/src/debug.c b/src/debug.c index e227867..87b3aff 100644 --- a/src/debug.c +++ b/src/debug.c @@ -50,3 +50,12 @@ void d_bitprint (int bits, int nr) { printf (" "); }; + +void d_fatal (char *fmt,...) { + va_list args; + + va_start (args, fmt); + fprintf (stdout, "FATAL:"); + vfprintf (stdout, fmt, args); + va_end (args); +} diff --git a/src/field.c b/src/field.c index eb03936..002fb9c 100644 --- a/src/field.c +++ b/src/field.c @@ -1,4 +1,4 @@ -/* $Id: field.c,v 1.29 2003/06/07 14:33:04 stpohle Exp $ */ +/* $Id: field.c,v 1.30 2003/06/07 19:05:55 stpohle Exp $ */ /* field.c - procedures which are needed to control the field */ #include @@ -19,6 +19,11 @@ draw_stone (int x, int y) int i, d; + if (x < 0 || y < 0 || x > bman.fieldsize.x || y > bman.fieldsize.y) { + d_fatal ("Draw Stone out of range [%d,%d]\n", x, y); + return; + } + src.w = dest.w = gfx.block.x; src.h = dest.h = gfx.block.y; @@ -77,9 +82,9 @@ draw_stone (int x, int y) if (i >= FT_death) { field_animation_add (x, y); srcimg = gfx.powerup[d].image; - if ((stone->frame & 0xFF) >= gfx.powerup[d].frames) + if (stone->frame >= gfx.powerup[d].frames) stone->frame = 0; - src.y = (stone->frame & 0xFF) * gfx.block.y; + src.y = stone->frame * gfx.block.y; } if (srcimg != NULL) diff --git a/src/packets.c b/src/packets.c index be80260..11b3119 100644 --- a/src/packets.c +++ b/src/packets.c @@ -619,6 +619,7 @@ do_bombdata (struct pkg_bombdata *b_dat, _net_addr * addr) bomb->r = b_dat->r; bomb->ex_nr = b_dat->ex_nr; bomb->state = b_dat->state; + if (bomb->state == BS_exploding) bomb_explode (b_dat->p_nr, b_dat->b_nr, 0); diff --git a/src/player.c b/src/player.c index 057a2e9..fd545fd 100644 --- a/src/player.c +++ b/src/player.c @@ -12,6 +12,13 @@ draw_player (_player * player) dest; int i; + if ((player->pos.x >> 8) < 0 || (player->pos.x >> 8) > bman.fieldsize.x || + (player->pos.y >> 8) < 0 || (player->pos.y >> 8) > bman.fieldsize.y) { + d_fatal ("Draw Player out of range : [%d,%d]\n", (player->pos.x >> 8), + (player->pos.y >> 8)); + return; + } + if (PS_IS_alife (player->state)) { /* player is alife */ dest.w = src.w = player->gfx->size.x; @@ -25,7 +32,7 @@ draw_player (_player * player) src.x = player->d * player->gfx->size.x; src.y = player->frame * player->gfx->size.y; SDL_BlitSurface (player->gfx->ani.image, &src, gfx.screen, &dest); - + /* if the player is ill, draw this image above him */ if (PS_IS_alife (player->state)) { for (i = PI_max - 1; (i >= 0) && (player->ill[i].to == 0); i--); @@ -44,22 +51,22 @@ draw_player (_player * player) } } } - + else { - /* player is dead */ + /* player is dead */ dest.w = src.w = gfx.dead.image->w; dest.h = src.h = player->gfx->size.y; - + dest.x = gfx.offset.x + player->gfx->offset.x + (player->pos.x >> 8) * gfx.block.x + gfx.postab[player->pos.x & 255]; dest.y = gfx.offset.y + player->gfx->offset.y + (player->pos.y >> 8) * gfx.block.y + gfx.postab[player->pos.y & 255]; - + src.x = 0; src.y = (2 * gfx.block.y) * player->frame; - + SDL_BlitSurface (gfx.dead.image, &src, gfx.screen, &dest); } gfx_AddUpdateRect (dest.x, dest.y, dest.w, dest.h); @@ -78,32 +85,41 @@ restore_players_screen () y, ys, ye; + for (i = 0; i < MAX_PLAYERS; i++) if ((PS_IS_used (bman.players[i].state)) && bman.players[i].old.x != -1) { - if ((bman.players[i].old.x & 0xFF) > 128) { - x = (bman.players[i].old.x >> 8); - xe = (bman.players[i].old.x >> 8) + 2; - } + + if ((bman.players[i].old.x >> 8) < 0 || (bman.players[i].old.x >> 8) > bman.fieldsize.x + || (bman.players[i].old.y >> 8) < 0 + || (bman.players[i].old.y >> 8) > bman.fieldsize.y) + d_fatal ("Restore Player out of range : playernr %d [%d,%d]\n", i, + (bman.players[i].old.x >> 8), (bman.players[i].old.y >> 8)); else { - x = (bman.players[i].old.x >> 8) - 1; - xe = (bman.players[i].old.x >> 8) + 1; + if ((bman.players[i].old.x & 0xFF) > 128) { + x = (bman.players[i].old.x >> 8); + xe = (bman.players[i].old.x >> 8) + 2; + } + else { + x = (bman.players[i].old.x >> 8) - 1; + xe = (bman.players[i].old.x >> 8) + 1; + } + if (x < 0) + x = 0; + if (xe >= bman.fieldsize.x) + xe = bman.fieldsize.x - 1; + ys = (bman.players[i].old.y >> 8) - 1; + ye = (bman.players[i].old.y >> 8) + 1; + if (ys < 0) + ys = 0; + if (ye >= bman.fieldsize.y) + ye = bman.fieldsize.y - 1; + xs = x; + for (; x <= xe; x++) + for (y = ys; y <= ye; y++) + draw_stone (x, y); + gfx_AddUpdateRect (xs * gfx.block.x + gfx.offset.x, ys * gfx.block.y + gfx.offset.y, + gfx.block.x * 3, gfx.block.y * 3); } - if (x < 0) - x = 0; - if (xe >= bman.fieldsize.x) - xe = bman.fieldsize.x - 1; - ys = (bman.players[i].old.y >> 8) - 1; - ye = (bman.players[i].old.y >> 8) + 1; - if (ys < 0) - ys = 0; - if (ye >= bman.fieldsize.y) - ye = bman.fieldsize.y - 1; - xs = x; - for (; x <= xe; x++) - for (y = ys; y <= ye; y++) - draw_stone (x, y); - gfx_AddUpdateRect (xs * gfx.block.x + gfx.offset.x, ys * gfx.block.y + gfx.offset.y, - gfx.block.x * 3, gfx.block.y * 3); } }; @@ -121,7 +137,7 @@ player_check_powerup (int p_nr) if (PS_IS_netplayer (p->state)) return; - + /* Get the right field position */ if (_x > 128) fx = fx + 1; @@ -204,7 +220,7 @@ check_field (short int fx, short int fy, _player * p) { _point bombs[MAX_PLAYERS * MAX_BOMBS]; int res = 0; - + if (bman.field[fx][fy].type != FT_stone && bman.field[fx][fy].type != FT_block) res = 1; get_bomb_on (fx, fy, bombs); @@ -400,12 +416,12 @@ player_died (_player * player, signed char dead_by) // player die ! d_printf ("player_died (%10s)\n", player->name); - + bman.updatestatusbar = 1; // force an update if (PS_IS_alife (player->state) && dead_by >= 0 && dead_by < MAX_PLAYERS) if (bman.p_nr != dead_by) bman.players[dead_by].points++; - player->frame = 0; + player->frame = 0; player->state &= (0xFF - PSF_alife); player->dead_by = dead_by; if (GT_MP_PTP) @@ -431,25 +447,25 @@ player_animation (_player * player) { if (player->gfx == NULL) return; - - if (PS_IS_alife (player->state)) { - if (player->frame < player->gfx->ani.frames - && (player->frameto <= 0 || player->frameto > ANI_PLAYERTIMEOUT)) { - player->frameto = ANI_PLAYERTIMEOUT; - player->frame++; - } - if (player->frame >= player->gfx->ani.frames) - player->frame = 0; - } - - if (PS_IS_dead (player->state)) { - if (player->frame < gfx.dead.frames - && (player->frameto <= 0 || player->frameto > ANI_PLAYERTIMEOUT * 2)) { - player->frameto = ANI_PLAYERTIMEOUT * 2; - player->frame++; - } - } - + + if (PS_IS_alife (player->state)) { + if (player->frame < player->gfx->ani.frames + && (player->frameto <= 0 || player->frameto > ANI_PLAYERTIMEOUT)) { + player->frameto = ANI_PLAYERTIMEOUT; + player->frame++; + } + if (player->frame >= player->gfx->ani.frames) + player->frame = 0; + } + + if (PS_IS_dead (player->state)) { + if (player->frame < gfx.dead.frames + && (player->frameto <= 0 || player->frameto > ANI_PLAYERTIMEOUT * 2)) { + player->frameto = ANI_PLAYERTIMEOUT * 2; + player->frame++; + } + } + if (player->frameto > 0) player->frameto--; }; @@ -542,7 +558,7 @@ player_ilness_loop (int pl_nr) tmp, send; int pl[MAX_PLAYERS + 1]; - + /* do the illness for the network players */ if (GT_MP_PTP) { for (pnr = 0; pnr < MAX_PLAYERS; pnr++) @@ -561,7 +577,7 @@ player_ilness_loop (int pl_nr) } } } - + /* check if we have contact with an other ill player */ p = &bman.players[pl_nr]; get_player_on (p->pos.x, p->pos.y, pl);