From: Holger Schemel Date: Sun, 19 Feb 2023 00:30:03 +0000 (+0100) Subject: fixed bug that could cause an endless loop (freeze) in the MM engine X-Git-Tag: 4.3.5.1^0 X-Git-Url: https://git.artsoft.org/rocksndiamonds.git/?a=commitdiff_plain;h=443ff08ee0c81730c4ff198b16bafc4199696724;hp=487e1b8ecea9121a3408e5d4f968945e071aa4aa;p=rocksndiamonds.git fixed bug that could cause an endless loop (freeze) in the MM engine This is a workaround for a regression bug of commit f8aec447 (that fixed overloading the laser due to duplicated tiles in damage list). The problem that could cause an endless loop already existed before the above commit, but without that commit, scanning the laser was stopped by the damage list completely filling up, stopping the loop. The above commit prevents adding the same tile again and again to the damage list, therefore not stopping the endless loop anymore. This commit should prevent the endless loop from happening at all. The problem (and how to reproduce it) was described by Eizzoux in the following post in the R'n'D web forum: https://www.artsoft.org/forum/viewtopic.php?p=18214 --- diff --git a/src/game_mm/mm_game.c b/src/game_mm/mm_game.c index 9a7ad5e6..2805fb77 100644 --- a/src/game_mm/mm_game.c +++ b/src/game_mm/mm_game.c @@ -1496,6 +1496,8 @@ boolean HitElement(int element, int hit_mask) // this is more precise: check if laser would go through the center if ((ELX * TILEX + 14 - LX) * YS != (ELY * TILEY + 14 - LY) * XS) { + int skip_count = 0; + // prevent cutting through laser emitter with laser beam if (IS_LASER(element)) return TRUE; @@ -1505,15 +1507,18 @@ boolean HitElement(int element, int hit_mask) { LX += XS; LY += YS; + + skip_count++; } while (ELX == LX/TILEX && ELY == LY/TILEY && LX > 0 && LY > 0); - if (LX/TILEX > ELX || LY/TILEY > ELY) + if ((LX/TILEX > ELX || LY/TILEY > ELY) && skip_count > 1) { /* skipping scan positions to the right and down skips one scan position too much, because this is only the top left scan position of totally four scan positions (plus one to the right, one to the bottom and one to the bottom right) */ + /* ... but only roll back scan position if more than one step done */ LX -= XS; LY -= YS;