Scratch-vm: Scratch 3.0 projects slowly get off sync

Created on 18 Jan 2018  路  5Comments  路  Source: LLK/scratch-vm

Expected Behavior

In 2.0, the actions of the duplicate sprites stay in sync

Actual Behavior

In 3.0, the costume changes slowly get out of sync, and the speech bubble changes get out of sync faster.

Consider this project:
https://scratch.mit.edu/projects/198464093/
https://llk.github.io/scratch-gui#198464093

They get out of sync especially fast in Edge, but it happens on other browsers too.
ezgif com-optimize

Steps to Reproduce

Have a sprite that repeats something every x seconds
Duplicate it
Run them both at the same time

Operating System and Browser

Windows 10 Edge


Moved from LLK/scratch-gui#1296
/cc @fsih

bug performance

All 5 comments

/cc @mzgoddard

Fixed the scratch-gui link

I updated the project so that they're saying the same thing, so it's easier to compare

I kept thinking about this issue and forgetting to at least write what I think is contributing to this. The wait block uses setTimeout. A 0.015 second wait will wait one frame. A 2 second wait will wait approximately 60 frames. At 30 FPS, the frames tick about every 33 milliseoncds with setInterval. setTimeout and setInterval can't guarantee that they'll run exactly X milliseconds after they were scheduled. More likely they will be late. Over 2 seconds, 59 frames may have been executed and drawn instead of the intended 60 to keep these two things in sync.

Wait and other blocks that delay what follows them, should probably use some internal timer. Like a runtime.timeout method. timeout could store a function like setTimeout and use the delay argument to determine a future time, the current internal time + the delay, to call the callback function. At the end of every runtime step, runtime will increment the internal time and compare to the future values saved by timeout when the internal time is larger than the saved future time, call the callback and remove that item from the stored list of timeouts.

This also affects the wait block, it might be related. See 134129247 (costume changes faster in 3.0)

Was this page helpful?
0 / 5 - 0 ratings