support icon indicating copy to clipboard operation
support copied to clipboard

[Bug] Repeated calling of hub.display.animate() would cause Spike Hub to hang.

Open davidwu226 opened this issue 2 years ago • 5 comments

Describe the bug

If I call hub.display.animate() repeatedly, the Spike Hub sometimes hang. Hitting the center button does not stop the program nor does hitting the stop button in the IDE. I will have to take out the battery in order to reset the hub.

To reproduce

from pybricks.hubs import PrimeHub
from pybricks.tools import wait, Matrix

hub = PrimeHub()
delay = 10

x = Matrix([
    [255,255,255,255,255],
    [255,  0,  0,  0,  0],
    [255,  0,  0,  0,  0],
    [255,  0,  0,  0,  0],
    [255,  0,  0,  0,  0],
])

while True:
    hub.display.animate([x, x], 10)
    wait(delay)

Run the above and try to hit the center button to stop the program. If it works, try again (or turn off the hub and start it again).

Expected behavior I should be able to stop the hub using the center button or by hitting stop in the IDE.

davidwu226 avatar Nov 21 '23 23:11 davidwu226

Thank you.

Can you please report the result of this script?

from pybricks import version
print(version)

We recently fixed something like this, so hopefully we're all good when we release this new version.

laurensvalk avatar Nov 22 '23 06:11 laurensvalk

I can confirm that this is still an issue with the latest release candidate as well. Thanks for reporting!

This also appears to be another case where the MicroPython system abort is not working, so maybe we should revert that one at some point too.

laurensvalk avatar Nov 22 '23 08:11 laurensvalk

The issue seems to only occur if it is called again before the first frame update.

This adapted script always works correctly for any delay > 0.

from pybricks.hubs import PrimeHub
from pybricks.tools import wait, Matrix

hub = PrimeHub()
delay = 5

x = Matrix([
    [255,255,255,255,255],
    [255,  0,  0,  0,  0],
    [255,  0,  0,  0,  0],
    [255,  0,  0,  0,  0],
    [255,  0,  0,  0,  0],
])

while True:
    hub.display.animate([x, x], delay)
    wait(delay + 1)

laurensvalk avatar Nov 22 '23 08:11 laurensvalk

Simple color animations are also affected, so we must have had this bug for a long time :smile:

from pybricks.hubs import PrimeHub
from pybricks.parameters import Color
from pybricks.tools import wait

hub = PrimeHub()

while True:
    hub.light.animate([Color.RED, Color.GREEN, Color.NONE], interval=10)
    wait(10)

laurensvalk avatar Nov 22 '23 09:11 laurensvalk

This also appears to be another case where the MicroPython system abort is not working, so maybe we should revert that one at some point too.

This is only partially true. Running the color animation is escapable with the old system abort (3.3b6) but the matrix animation isn't. This was already broken in Pybricks 3.2.

It could also be another case where running the pbio event loop happens while renewing the memory for the animation in common_LightMatrix_animate.

laurensvalk avatar Nov 22 '23 09:11 laurensvalk