Skip to content

Commit a19c75f

Browse files
committed
Add bound checks for render_block
1 parent ed65a07 commit a19c75f

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

stage.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -518,8 +518,16 @@ def tick(self):
518518
def render_block(self, x0=0, y0=0, x1=None, y1=None):
519519
if x1 is None:
520520
x1 = self.width
521+
else:
522+
x1 = min(max(1, x1), self.width)
521523
if y1 is None:
522524
y1 = self.height
525+
else:
526+
y1 = min(max(1, y1), self.height)
527+
x0 = min(max(0, x0), self.width - 1)
528+
y0 = min(max(0, y0), self.height - 1)
529+
if x0 >= x1 or y0 >= y1:
530+
return
523531
layers = [l.layer for l in self.layers]
524532
with self.display as display:
525533
display.block(x0 * self.scale, y0 * self.scale,
@@ -539,7 +547,7 @@ def render_sprites(self, sprites):
539547
max(sprite.px, int(sprite.x)) + 16))
540548
y1 = max(1, min(self.height,
541549
max(sprite.py, int(sprite.y)) + 16))
542-
if x0 == x1 or y0 == y1:
550+
if x0 >= x1 or y0 >= y1:
543551
continue
544552
display.block(x0 * self.scale, y0 * self.scale,
545553
x1 * self.scale - 1, y1 * self.scale - 1)

0 commit comments

Comments
 (0)