Skip to content

Commit 717e841

Browse files
draw: prevent crash due to drawing out of bounds
1 parent 40dd2b0 commit 717e841

File tree

1 file changed

+6
-1
lines changed
  • internal_filesystem/apps/com.example.draw/assets

1 file changed

+6
-1
lines changed

internal_filesystem/apps/com.example.draw/assets/draw.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ def get_xy():
8888
else:
8989
return indev_error_x,indev_error_y # make it visible that this occurred
9090

91+
# doesnt work:
9192
def draw_line(x, y):
9293
global canvas
9394
# Line drawing like this doesn't work:
@@ -145,7 +146,11 @@ def touch_cb(event):
145146
for dx in range(-radius, radius):
146147
for dy in range(-radius, radius):
147148
if dx * dx + dy * dy <= square:
148-
canvas.set_px(x + dx, y + dy, DARKPINK, lv.OPA.COVER)
149+
newx, newy = x + dx, y + dy
150+
if 0 <= newx <= hor_res and 0 <= newy <= ver_res:
151+
canvas.set_px(x + dx, y + dy, DARKPINK, lv.OPA.COVER)
152+
else:
153+
print(f"Not drawing outside of canvas at {newx},{newy} because that crashes.")
149154

150155

151156
canvas = lv.canvas(appscreen)

0 commit comments

Comments
 (0)