From: Holger Schemel Date: Wed, 19 Jun 2019 17:47:22 +0000 (+0200) Subject: fixed crash bug caused by division by zero X-Git-Tag: 4.1.4.0~25 X-Git-Url: https://git.artsoft.org/?p=rocksndiamonds.git;a=commitdiff_plain;h=baed6f0a85ade21358cde876c3c044c34749c434 fixed crash bug caused by division by zero This bug will crash the program when loading a graphics set which uses toon animation step delay values of zero (instead of positive integers as it should be). This bug was introduced around version 4.0.0.0 when adding global animations (treating toon animations as special global animations), which could result in animation delay values of zero even though this was checked and corrected when reading the graphics config file. --- diff --git a/src/anim.c b/src/anim.c index 14dccc69..3e2f1222 100644 --- a/src/anim.c +++ b/src/anim.c @@ -242,6 +242,9 @@ int getAnimationFrame(int num_frames, int delay, int mode, int start_frame, { int frame = 0; + if (delay < 1) // delay must be at least 1 + delay = 1; + sync_frame += start_frame * delay; if (mode & ANIM_LOOP) // looping animation diff --git a/src/init.c b/src/init.c index eb18b6da..a022f394 100644 --- a/src/init.c +++ b/src/init.c @@ -1476,7 +1476,7 @@ static void set_graphic_parameters_ext(int graphic, int *parameter, else g->anim_frames = 1; - if (g->anim_frames == 0) // frames must be at least 1 + if (g->anim_frames < 1) // frames must be at least 1 g->anim_frames = 1; g->anim_frames_per_line = @@ -1484,7 +1484,7 @@ static void set_graphic_parameters_ext(int graphic, int *parameter, parameter[GFX_ARG_FRAMES_PER_LINE] : anim_frames_per_line); g->anim_delay = parameter[GFX_ARG_DELAY]; - if (g->anim_delay == 0) // delay must be at least 1 + if (g->anim_delay < 1) // delay must be at least 1 g->anim_delay = 1; g->anim_mode = parameter[GFX_ARG_ANIM_MODE]; @@ -1552,6 +1552,9 @@ static void set_graphic_parameters_ext(int graphic, int *parameter, g->x = parameter[GFX_ARG_X]; // (may be uninitialized, g->y = parameter[GFX_ARG_Y]; // unlike src_x and src_y) + if (g->step_delay < 1) // delay must be at least 1 + g->step_delay = 1; + // this is only used for drawing font characters g->draw_xoffset = parameter[GFX_ARG_DRAW_XOFFSET]; g->draw_yoffset = parameter[GFX_ARG_DRAW_YOFFSET];