michaelvillar / dynamics.js

Javascript library to create physics-based animations
http://dynamicsjs.com
7.57k stars 414 forks source link

Some strange error occured #17

Closed fobdy closed 8 years ago

fobdy commented 8 years ago

I've been writing some tests and got some error occured in karma test Chrome environment.

var $elem = document.querySelector('.message');
dynamics.animate($elem, {
    scale: 1.5
  }, {
    type: dynamics.bounce,
    frequency: 450,
    friction: 200,
    duration: 1000
})

Will raise following error in karma Chrome:

Uncaught TypeError: Cannot read property '0' of undefined
    DecomposedMatrix.interpolate @ index.js:17591
    __bind @ index.js:16817
    interpolate @ index.js:18198
    animationTick @ index.js:18181
    runLoopTick @ index.js:18149

It fails on the following line src/dynamics.coffee#L495

decomposed[k][i] = (decomposedB[k][i] - decomposedA[k][i]) * t + decomposedA[k][i];

I've dived into code and find that it's because decomposedB.transform is false, so decomposedB['transform'][0] cannot be evaulated.

The decomposedB is set to false in startAnimation with following line:

endProperties['transform'] = matrix.decompose(); 

matrix is created with

matrix = Matrix.fromTransform(Matrix.matrixForTransform(v));

v is "scaleX(1.5) scaleY(1.5) scaleZ(1.5)"

And later matrix.decompose() returns false because of this statement:

if (els[3][3] === 0) {
  return false;
}

So if this is normal, then problem with some if statement in for cycle:

if !only? or only.indexOf(k) > -1 or only.indexOf("#{k}#{['x','y','z'][i]}") > -1

In original non karma environment everything works fine, but few conditions is not the same.

michaelvillar commented 8 years ago

I never used Karma before, can you tell me the steps to reproduce?

fobdy commented 8 years ago

Ok, i'll try to compose some minimal demo

michaelvillar commented 8 years ago

Thank you!

michaelvillar commented 8 years ago

Ping!

fobdy commented 8 years ago

Ok, sorry. I'll try to replay this on newer versions of karma & chrome

michaelvillar commented 8 years ago

Please reopen this if you give more information ;)