JUCE
JUCE copied to clipboard
Fix javascript bad interrupt
This proposes a fix for the issue #1445
The execute() function sets an interrupt in the engine that is then checked whenever a function is called using callFunction, but the interval in the interrupt check function is calculated depending on the time at execute(), not the time at callFunction(), resulting in an inevitable interrupt if we keep calling functions after having calling execute() once.
This fix store a "timeAtLastStart" variable that replaces the lambda-local "started" argument. This way, it is effectively updated everytime an evaluate / execute / callFunction is used, without having to redefine the engine interrupt handler everytime.
A more complete and possibly elegant implementation would be to keep track of which thread has called what and have different checks for each thread, so they can be treated independently. But this fix is way simpler and should be good for most cases.