From 717e841c81d78a9fc959b3aefe5873ec6a7bea21 Mon Sep 17 00:00:00 2001 From: Thomas Farstrike Date: Sat, 10 May 2025 17:58:19 +0200 Subject: [PATCH] draw: prevent crash due to drawing out of bounds --- internal_filesystem/apps/com.example.draw/assets/draw.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/internal_filesystem/apps/com.example.draw/assets/draw.py b/internal_filesystem/apps/com.example.draw/assets/draw.py index 9a4930dc..b926f13f 100644 --- a/internal_filesystem/apps/com.example.draw/assets/draw.py +++ b/internal_filesystem/apps/com.example.draw/assets/draw.py @@ -88,6 +88,7 @@ def get_xy(): else: return indev_error_x,indev_error_y # make it visible that this occurred +# doesnt work: def draw_line(x, y): global canvas # Line drawing like this doesn't work: @@ -145,7 +146,11 @@ def touch_cb(event): for dx in range(-radius, radius): for dy in range(-radius, radius): if dx * dx + dy * dy <= square: - canvas.set_px(x + dx, y + dy, DARKPINK, lv.OPA.COVER) + newx, newy = x + dx, y + dy + if 0 <= newx <= hor_res and 0 <= newy <= ver_res: + canvas.set_px(x + dx, y + dy, DARKPINK, lv.OPA.COVER) + else: + print(f"Not drawing outside of canvas at {newx},{newy} because that crashes.") canvas = lv.canvas(appscreen)