Skip to content

Commit

Permalink
Limit drawn parallax tiles to prevent potential infinite loop
Browse files Browse the repository at this point in the history
  • Loading branch information
AntumDeluge committed May 28, 2024
1 parent f7321aa commit bcacec3
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/js/stendhal/landscape/ParallaxBackground.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit bcacec3

Please sign in to comment.