From bcacec37198496f1edeb9049851de7a8d7362c05 Mon Sep 17 00:00:00 2001 From: Jordan Irwin Date: Tue, 28 May 2024 10:37:20 -0700 Subject: [PATCH] Limit drawn parallax tiles to prevent potential infinite loop --- src/js/stendhal/landscape/ParallaxBackground.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/js/stendhal/landscape/ParallaxBackground.ts b/src/js/stendhal/landscape/ParallaxBackground.ts index 545a882095..076d1933e1 100644 --- a/src/js/stendhal/landscape/ParallaxBackground.ts +++ b/src/js/stendhal/landscape/ParallaxBackground.ts @@ -64,9 +64,9 @@ export class ParallaxBackground { const tileLeftStart = offsetX - ((offsetX / 4) % this.image.width); let tileTop = offsetY - ((offsetY / 4) % this.image.height); - while (tileTop - offsetY < ctx.canvas.height) { + for (let yidx = 0; yidx < 100 && tileTop - offsetY < ctx.canvas.height; yidx++) { let tileLeft = tileLeftStart; - while (tileLeft - offsetX < ctx.canvas.width) { + for (let xidx = 0; xidx < 100 && tileLeft - offsetX < ctx.canvas.width; xidx++) { ctx.drawImage(this.image, tileLeft, tileTop); tileLeft += this.image.width; }