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

Music: fix for infinite loop when loop field cleared #48877

Merged
merged 1 commit into from
Oct 27, 2022

Conversation

breville
Copy link
Member

Screenshot 2022-10-26 at 10 56 11 PM

When the "by" field was cleared, an infinite loop would occur, due to the generated code including something like this:

for (i = 1; i <= 3; i += 0)

The issue is subtle, but it turns out that Blockly.JavaScript.valueToCode was returning '0', and while '0' == false might be true, '0' || '1' will return '0'.

The simple fix here is to use the unary plus operator to convert the '0' to 0. Then we will fall back to '1' when the field is blank.

Copy link
Contributor

@sanchitmalhotra126 sanchitmalhotra126 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch! I think this was just copied from the blockly source so I wonder if this is a bug in Blockly as well...

@breville breville merged commit 8d259b7 into staging Oct 27, 2022
@breville breville deleted the music-fix-infinite-loop branch October 27, 2022 19:53
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

Successfully merging this pull request may close these issues.

None yet

3 participants