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

Infinite loop with SCRIPT #34

Closed
samdoshi opened this issue Apr 10, 2016 · 4 comments
Closed

Infinite loop with SCRIPT #34

samdoshi opened this issue Apr 10, 2016 · 4 comments
Assignees

Comments

@samdoshi
Copy link
Collaborator

@samdoshi samdoshi commented Apr 10, 2016

There is some protection against causing an infinite recursion loop with the SCRIPT op, but it's easily worked around, e.g.

1:

SCRIPT 2

2:

SCRIPT 3

3:

SCRIPT 1

If you trigger script 1, you will lock up the device. (Worse if someone does this in the I script for the power on preset, you'll need to flash to recover)

The problem will only be worse with timelines, so we need to rethink how we deal with this.

One alternative could be to allow a maximum number of commands to be executed by an external event (e.g. trigger, metronome, delayed commands), and then not worry about the infinite loop.

@tehn
Copy link
Member

@tehn tehn commented Apr 11, 2016

ahh. the script_caller set/reset needs to be repaired, you are correct.

int8_t script_caller;
static void tele_script(uint8_t a) {
    if (!script_caller) {
        script_caller = a;
        for (int i = 0; i < script[a - 1].l; i++) process(&script[a - 1].c[i]);
    }
    else if (a != script_caller) {
        for (int i = 0; i < script[a - 1].l; i++) process(&script[a - 1].c[i]);
    }

    script_caller = 0;
}
@tehn
Copy link
Member

@tehn tehn commented Apr 11, 2016

the script_caller var should be set to zero only by the initiating call to tele_script.

@samdoshi
Copy link
Collaborator Author

@samdoshi samdoshi commented Apr 12, 2016

I think you'll still be able trigger infinite recursion so long as you don't visit the initiation script, e.g.

1:

SCRIPT 2

2:

SCRIPT 3

3:

SCRIPT 2

If you want to disallow any form of recursion, we need to track the call stack, at which point we can decide if we want to allow no recursion, or a limited amount.

If we go with no recursion we still need to stop running commands on call stack overflow so that we fail safe.

I'm planning on introducing the concept of an 'execution' context which can hold things like the call stack.

@samdoshi samdoshi self-assigned this Apr 12, 2016
@samdoshi
Copy link
Collaborator Author

@samdoshi samdoshi commented May 17, 2017

Fixed in #73

@samdoshi samdoshi closed this May 17, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants