Skip to content

FrameBuffer.ellipse goes into infinite loop with 0 radius #16053

@corranwebster

Description

@corranwebster

Port, board and/or hardware

unix, RP2

MicroPython version

MicroPython v1.23.0 on 2024-06-02; Raspberry Pi Pico with RP2040
MicroPython v1.23.0 on 2024-05-31; darwin [GCC 4.2.1] version

Reproduction

In an interactive session (or otherwise), run the following code:

import framebuf
buf = bytearray(10*10*2)
f = framebuf.FrameBuffer(buf, 10, 10, framebuf.RGB565)
f.ellipse(5, 5, 0, 0, 0xffff, True)

Expected behaviour

Nothing should be drawn. Code should complete normally.

Maybe an exception should be raised, but I think it's OK to just draw nothing.

Observed behaviour

Micropython hangs; 100% CPU usage observed in unix port. Strong suspicion this is an infinite loop.

Additional Information

I'm very suspicious of the following code:

while (stoppingx >= stoppingy) { // 1st set of points, y' > -1
draw_ellipse_points(self, args[0], args[1], x, y, args[4], mask);
y += 1;
stoppingy += two_asquare;
ellipse_error += ychange;
ychange += two_asquare;
if ((2 * ellipse_error + xchange) > 0) {
x -= 1;
stoppingx -= two_bsquare;
ellipse_error += xchange;
xchange += two_bsquare;
}
}

In this case two_asquare and two_bsquare are both 0, so the stoppingx and stoppingy look like they are never changed, but I haven't 100% proven it to myself.

Code of Conduct

Yes, I agree

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions