Comments (6)
So you see "2 end" but never "3 start" correct? No errors thrown?
from johnny-five.
So you see "2 end" but never "3 start" correct? No errors thrown?
That is correct, I can give you more insight if you wish. For some reason, I've added some console logs inside animation.js
file and I can see that this.segments.length
is going to 1
to 0
then to 2
then directly to 0
. I'm trying to investigate.
I suspect some kind of race conditions.
I think this could also be nice to buffer things before everything starts. Adding an autoStart
property might be a good choice.
If I can contribute, just let me know. I'm also doing a big work updating typescript definition typings DefinitelyTyped/DefinitelyTyped#67063
from johnny-five.
@dtex Any idea on that ?
from johnny-five.
I don't know if it's a race condition, or we're just popping things off the queue too aggressively. I'll set up a test and see if I can find where that's happening.
from johnny-five.
I don't know if it's a race condition, or we're just popping things off the queue too aggressively. I'll set up a test and see if I can find where that's happening.
Alright thank you very much, Keep me in touch, I would be really pleased because i need this feature, I'm trying debugging on my side.
from johnny-five.
@dtex Issue happen on
Line 94 in 094bf6c
Added this code
Constructor
class Animation extends Emitter {
constructor(target) {
super();
// Necessary to avoid loading temporal unless necessary
if (!temporal) {
temporal = require("temporal");
}
console.log("Before constructor assign", this.segments?.length)
Object.assign(this, new Animation.Segment());
console.log("After constructor assign", this.segments?.length)
this.defaultTarget = target || {};
}
Output is
worker:dev: [dev] Before constructor assign undefined
worker:dev: [dev] opts []
worker:dev: [dev] After constructor assign 0
This is initializing the array to 0, which is fine.
Segments shifting in loop
console.log("Before shift", this.segments.length)
const firstElement = this.segments.shift()
console.log("After Shift",this.segments.length)
Object.assign(this, new Animation.Segment(firstElement));
console.log("After assign",this.segments.length)
Output is
worker:dev: [dev] Before shift 1
worker:dev: [dev] After Shift 0
worker:dev: [dev] opts [ 'duration', 'keyFrames', 'onstart', 'oncomplete', 'target' ]
worker:dev: [dev] After assign 0
worker:dev: [dev] enqueue 1
worker:dev: [dev] enqueue 2
worker:dev: [dev] enqueue 3
worker:dev: [dev] enqueue 4
worker:dev: [dev] loopFunction 4
worker:dev: [dev] next 4
worker:dev: [dev] Before shift 4
worker:dev: [dev] After Shift 3
worker:dev: [dev] opts [ 'duration', 'keyFrames', 'onstart', 'oncomplete', 'target' ]
worker:dev: [dev] After assign 0
worker:dev: [dev] loopFunction 0
worker:dev: [dev] Stop called
It's 1
because the first instruction is queued, then 1
again because i have a total of 5 enqueued tasks. So when the first trigger 0, the other become 1,2,3,4.
stop
is called, so it pops out the this.segments
array.
loopFunction
console.log is from there and next
is from next
method.
if ((this.progress === 1 && !this.reverse) || (progress === this.loopback && this.reverse)) {
if (this.loop || (this.metronomic && !this.reverse)) {
if (this.onloop) {
this.onloop();
}
if (this.metronomic) {
this.reverse = this.reverse ? false : true;
}
this.normalizeKeyframes();
this.progress = this.loopback;
this.startTime = Date.now() - this.scaledDuration * this.progress;
this.endTime = this.startTime + this.scaledDuration;
} else {
this.isRunning = false;
if (this.oncomplete) {
process.nextTick(() => this.oncomplete());
}
console.log("loopFunction",this.segments.length)
if (this.segments.length > 0) {
process.nextTick(() => this.next());
} else {
this.stop();
}
FIXES
I've been able to fix the code doing this
Object.assign(this, new Animation.Segment(firstElement), {segments: this.segments});
We need to re-apply segments otherwise we crush the segment array each time. Or we need to pass current second to options so options.segments
can trigger inside Animation.Segment
I can make a pull request if you think it's okay.
from johnny-five.
Related Issues (20)
- Novice ask next how to upload js to hardware HOT 7
- Using PWM and AC DImmer RobotDyn
- Cannot Input Mode Pin 12, 14, 15. ESP8266 HOT 4
- Refactor DS18B20 Temperature Conversion Time Handling
- Usage with Electron of latest J5 versions? HOT 6
- Status of Release?
- Using a Coin selector
- CAN bus with mcp2515 support, and other libraries
- MKR 1010 board HOT 1
- INPUT_PULLUP on digital input pin HOT 12
- I2C Scanner?
- Input pull-up doesn't work on expanders HOT 1
- Unable to use Led.Digits with Multple Boards HOT 4
- Stop stepper while running HOT 2
- Calling animation.next inside onloop callback is not working.
- Sensor disable only works once. HOT 3
- Is there a way to use multiple I2C LCD's HOT 2
- RaspberryPi issue HOT 3
- Intermittent Error Code 31 in GetOverlappedResult
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from johnny-five.