From d6dc694dbdd5f269d2bb0105ab8b6c79131de11a Mon Sep 17 00:00:00 2001
From: iggy <iggy@muc.ccc.de>
Date: Sat, 3 Jun 2023 08:20:35 +0200
Subject: [PATCH] debugging ctx crash

---
 python_payload/application.py |  4 ++--
 python_payload/ui.py          | 19 +++++++++++++++++--
 2 files changed, 19 insertions(+), 4 deletions(-)

diff --git a/python_payload/application.py b/python_payload/application.py
index 2c9d2bb02c..37402d328f 100644
--- a/python_payload/application.py
+++ b/python_payload/application.py
@@ -121,7 +121,7 @@ class Application():
             e.set_enabled(enabled)
 
     def on_init(self):
-        print("nothing")
+        print("nothing to init")
         pass
 
     def on_foreground(self):
@@ -137,7 +137,7 @@ class Application():
         pass
 
     def main_foreground(self):
-        print("nothing")
+        #print("nothing")
         pass
     
     def main_always(self):
diff --git a/python_payload/ui.py b/python_payload/ui.py
index 3f42e65074..17ee606351 100644
--- a/python_payload/ui.py
+++ b/python_payload/ui.py
@@ -4,6 +4,9 @@ import math
 import time
 from math import sin,cos,pi
 
+import micropython
+import gc
+
 WIDTH = 240
 HEIGHT = 240
 
@@ -76,6 +79,7 @@ class Icon(UIElement):
         super().__init__()
 
     def _draw(self,pos):
+        print("ui.Icon._draw()")
         x = int(pos[0])
         y = int(pos[1])
 
@@ -89,6 +93,8 @@ class Icon(UIElement):
                 y-hs/2,
                 hs,hs,hs//2
             ).fill()
+        
+        print("  arc")
         self.ctx.move_to(x,y).rgb(self.bg_r,self.bg_g,self.bg_b).arc(x,y,self.size/2,-math.pi,math.pi,True).fill()
         #self.ctx.move_to(x,y-self.size/2).rgb(self.bg_r,self.bg_g,self.bg_b).
         #.round_rectangle(
@@ -96,8 +102,17 @@ class Icon(UIElement):
         #    y-self.size/2,
         #    self.size,self.size,self.size//2
         #).fill()
-        self.ctx.rgb(1,1,1).move_to(x,y).text(self.label)
-
+        micropython.mem_info()
+        gc.collect()
+        print(self.label)
+        
+        self.ctx.rgb(1,1,1).move_to(x,y)
+        micropython.mem_info("data")
+        print("  moved")
+        print(" crash here:")
+        self.ctx.text(self.label)
+        
+        print("  text")
 class IconValue(Icon):
     def __init__(self, value=0, *args, **kwargs):
         super().__init__(*args, **kwargs)
-- 
GitLab