earthoutreach / earth-api-utility-library

Automatically exported from code.google.com/p/earth-api-utility-library
0 stars 0 forks source link

fx.TimedAnimation Multiple Completion Calls #25

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Browser: FF 3.6.3 + Firebug 1.5.3
Gex Version: 0.2.1

=Test case:

var gex = new GEarthExtensions(ge);
var lookAt = gex.util.getLookAt();
var startLon = lookAt.getLongitude();
var animation = new gex.fx.TimedAnimation(1000, 
    function(t) {
        if(t == 1000) {
            console.log('render time = duration');
        }
        lookAt.setLongitude(startLon + t / 100);
        ge.getView().setAbstractView(lookAt);
    },
    function() {
        console.log('complete func')
    }
);
animation.start();

=Expected output:
Only one "complete func" in firebug.

=Actual output:
Two "complete func" (occurs randomly)

=console.log debug additions:

GEarthExtensions.prototype.fx.Animation.prototype.stop = function(completed) {
  this.extInstance.fx.getAnimationManager_().stopAnimation(this);
  console.log('animation stop');
  this.completionFn({
    cancelled: !Boolean(completed || geo.util.isUndefined(completed))
  });
};

GEarthExtensions.prototype.fx.TimedAnimation.prototype.renderFrame =
function(t) {
    console.log('render ' + t);
  if (this.complete) {
      console.log('render complete. return');
    return;
  }

  if (t > this.duration) {
      console.log('timed complete');
      console.log(this);
    this.renderFn.call(this, this.duration);
    this.stop();
    this.complete = true;
    return;
  }

  this.renderFn.call(this, t);
};

=Firebug output (from debugging above):

render 990
render 1001
timed complete
render time = duration
render 1005
timed complete
render time = duration
animation stop
complete func
animation stop
complete func

The view animation is necessary to invoke GE frameend calls. This results
in renderFrame() being called twice after the duration due to
window.setInterval and GE frameend ticks. This appears to be, as stated by
Nik, the root of the issue.

This is a race condition and (if you're unfortunate like me :) requires
multiple attempts before it shows its face. I see that there is a
this.complete flag and a check in renderFrame() but that check does not
result in true. I have a "render complete. return" debug in that if-block
but it does not show in the Firebug output above.

The interesting part is that it appears another renderFrame() call happens
right in the middle of the previous renderFrame() (they're both over 1000)
but the scope from the first renderFrame() doesn't appear to have exited..
it's almost as if it's being preempted which might be why the this.complete
lock/flag doesn't work in this case.

Please comment on your findings as I am interested in what exactly is
happening here.

Thanks!

Rob O.
Ender Tech Corp.

Original issue reported on code.google.com by ndrtek...@gmail.com on 4 Apr 2010 at 3:05

GoogleCodeExporter commented 8 years ago
Yea I have no idea what's going on here. Maybe an issue entirely provoked by 
Firebug
but here's a different test case:

var gex = new GEarthExtensions(ge);
var lookAt = gex.util.getLookAt();
var startLon = lookAt.getLongitude();
var callback = function() { console.log('complete'); }
for(i=0; i<100; i++) {
    console.log(i);
}
var animation = new gex.fx.TimedAnimation(1000, 
    function(t) {
        console.log(t);
        if(t == 1000) {
            console.log('render time = duration');
        }
        lookAt.setLongitude(startLon + t / 100);
        ge.getView().setAbstractView(lookAt);
    },
    function() {
        console.log('complete func');
        callback();
    }
);
animation.start();

Firebug output:

989
1000
render time = duration
1000
render time = duration
complete func
complete
complete func
complete

I can only get "complete func" to output twice if and only if I have 
console.log(t);
or I have I have the for-loop. I can get "render time = duration" twice but 
only one
"complete func" without both of those. Maybe Firebug is provoking a necessary 
delay
for the error to show or it might be some weird execution within Firebug. At one
point I got it to show three "complete func" calls.

Regardless, I would like for it not to call "complete func" twice while still 
having
all the debugging log calls throughout my code.

Thanks

Rob O.
Ender Tech Corp.
www.endertech.com

Original comment by ndrtek...@gmail.com on 4 Apr 2010 at 3:31

GoogleCodeExporter commented 8 years ago
Thanks for pointing out this issue with the duplicate complete under certain 
conditions.  I've confirmed the issue, but as it has a straightforward 
workaround (you can just catch the first complete, and then ignore the next 
one) I'm not planning to attempt a fix unless it seems to be causing some 
issues in production code that are not easily worked around.  If this is a 
showbreaker for your code, provide additional details.

Original comment by jli...@google.com on 4 Jan 2011 at 9:00