Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lockup using PicoVector arc function with Thonny #41

Open
p8mty opened this issue Jan 8, 2025 · 4 comments
Open

Lockup using PicoVector arc function with Thonny #41

p8mty opened this issue Jan 8, 2025 · 4 comments

Comments

@p8mty
Copy link

p8mty commented Jan 8, 2025

This has been discussed on the forums

https://forums.pimoroni.com/t/presto-picovector-issue/27032

Basically, running this code using Thonny:

from presto import Presto
from picovector import PicoVector, Polygon, Transform, ANTIALIAS_BEST

# Setup for the Presto display
presto = Presto(layers = 1, full_res=False, ambient_light=False)
display = presto.display

vector = PicoVector(display)

vector.set_antialiasing(ANTIALIAS_BEST)

WIDTH, HEIGHT = display.get_bounds()

# Couple of colours for use later
BLACK = display.create_pen(0,0,0)
BLUE = display.create_pen(0,0, 202)
RED = display.create_pen(200,0,0)
WHITE = display.create_pen(255, 255, 255)
GREEN = display.create_pen(0,255,0)
YELLOW = display.create_pen(0,255,255)


def draw_arc(x,y,r,q,c):
# x,y = centre, r = radius, q = quadrant, c = circle position
# if centre of flow at x,y, then calculate co-ord for arc centre
# and start and end angles
    if q == 1:
        xpos = x-r
        ypos = y-r
        astart = 0
        aend = 90
    elif q == 2:
        xpos = x+r
        ypos = y-r
        astart = 0
        aend = -90
    elif q == 3:
        xpos = x+r
        ypos = y+r
        astart = 180
        aend = 270
    elif q == 4:
        xpos = x-r
        ypos = y+r
        astart = 90
        aend = 180
    arc_a = Polygon()
    arc_a.arc(xpos,ypos,r, astart, aend, 2)
#    arc_a.circle(xpos,ypos,r,3)
    
    vector.draw(arc_a)
 

# Clear the screen and use blue as the background colour
display.set_pen(BLUE)
display.clear()
display.set_pen(WHITE)
xpos=120
ypos=100
radius = 75
sc = 0.7

for i in range(1,100):
    print(i)
    display.set_pen(BLACK)
    display.clear()
    display.set_pen(RED)
    print("arc 1")
    draw_arc(xpos,ypos,radius,1,i)
    display.set_pen(BLUE)
    print("arc 2")
    draw_arc(xpos,ypos,radius,2,int(i/2))
    display.set_pen(GREEN)
    print("arc 3")
    draw_arc(xpos,ypos,radius,3,int(i/5))
    display.set_pen(YELLOW)
    print("arc 4")
    draw_arc(xpos,ypos,radius,4,int((i*5) % 90))
    presto.update()

Will cause my Presto lockup on the second run of the code after a couple of iterations through the loop.

If I don't run it under Thonny, it's OK. If I draw a circle instead of the arc, it's OK. I've tried lots of debugging and it has the "feel" of being a memory issue, but I have no direct evidence of that.

I'm using the most recent firmware:

MicroPython feature/presto-wireless, presto v0.0.5 on 2024-12-18; Presto with RP2350
@Gadgetoid
Copy link
Member

"feel" of being a memory issue, but I have no direct evidence of that

The number of times I've had this feeling and it's panned out to be a memory issue suggests you're probably right.

@MichaelBell
Copy link
Collaborator

The problem looks to be that ppp_arc uses raw calloc and free, not PP_MALLOC and PP_FREE.

@Gadgetoid
Copy link
Member

Tagged a release to hopefully slurp up this fix - https://github.com/pimoroni/presto/releases/tag/v0.0.6

@p8mty
Copy link
Author

p8mty commented Jan 8, 2025

Thanks for your quick work on fixing this. (And for saving my sanity!)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants