Skip to content

onEveryBeatDo interval not cleared on Stop due to bypassing ManagedTimer #7222

@sahu-virendra-1908

Description

@sahu-virendra-1908

Description

While testing onEveryBeatDo, I noticed that the beat callback continues to run even after pressing the Stop button.

After looking into the code, it seems that the interval created for onEveryBeatDo is using the browser’s native setInterval instead of the internal _timerManager.

Because of this, when Stop is pressed, _timerManager.clearAll() does not cancel this interval, and the beat callback keeps running.

In addition, the interval reference is not reset after stopping, which can lead to multiple intervals being created across Play/Stop cycles.

Reference (interval created using raw setInterval):

Expected Behavior

Pressing Stop should cancel all running callbacks, including onEveryBeatDo
No beat events should fire after stopping
Restarting the program should not create duplicate intervals

Actual Behavior

Beat callback continues even after pressing Stop
After multiple Play/Stop cycles, callbacks may run multiple times
Leads to unexpected logs or overlapping audio events

How to Reproduce

Open Music Blocks
Add a start block
Add an onEveryBeatDo block (e.g., print "BEAT")
Click Play
Wait 2–3 seconds
Click Stop
Open console

You will see "BEAT" still printing after Stop

Press Play and Stop again

You may observe multiple prints per beat

Console log Errors:

Repeated logs even after Stop
No explicit error, but behavior is incorrect

Environment:

Operating System: Windows
Browser: Chrome
Version: Latest (master branch)

Checklist

I have read and followed the project's code of conduct.
I have searched for similar issues before creating this one.
I have provided all the necessary information to understand and reproduce the issue.
I am willing to contribute to the resolution of this issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    Status

    Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions