gorlok / java-universal-tween-engine

Automatically exported from code.google.com/p/java-universal-tween-engine
0 stars 0 forks source link

Callback not called after killing another timeline that called it. #8

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?

see class below.

What is the expected output? What do you see instead?

expected:

call #1
call #2

actual:

call #1

What version of the product are you using? On what operating system?

6.3.1
Ubuntu, java-6-openjdk-amd64

Please provide any additional information below.

As far as I understand it, the code below should cause the callback to get 
called twice. When I run it I only get it called once. Am I doing something 
wrong?

Thanks

import aurelienribon.tweenengine.BaseTween;
import aurelienribon.tweenengine.Timeline;
import aurelienribon.tweenengine.Tween;
import aurelienribon.tweenengine.TweenCallback;
import aurelienribon.tweenengine.TweenManager;

public class Main
{
    private static TweenCallback callback = new TweenCallback()
    {
        private int n = 0;

        @Override
        public void onEvent(int type, BaseTween<?> source)
        {
            n++;
            System.out.println("call #" + n);
        }
    };

    public static void main (String args[]) throws Exception 
    {
        TweenManager m = new TweenManager();

        Timeline t = Timeline.createSequence()
                .push(Tween.call(callback))
                .start(m);

        for(int n = 0; n < 1000; n++)
            m.update(1);

        t.kill();
        t = null;

        t = Timeline.createSequence()
                .push(Tween.call(callback))
                .start(m);

        for(int n = 0; n < 1000; n++)
            m.update(1);
    }   
}

Original issue reported on code.google.com by felixwatts on 16 May 2012 at 2:53

GoogleCodeExporter commented 8 years ago
That's not a bug, that's a feature :p
Actually you're keeping a reference to the Timeline "t" long after it's been 
destroyed and reset by the manager. Therefore, when you call "kill()" on it, 
you're killing a random timeline which is waiting in the pool. When you create 
the second timeline, the engine reuse the first object, but it is already 
killed and so is immediately sent back to the pool by the manager.

Actually you found a bug. In previous versions of the engine, I reset the 
tweens/timelines on pooling but also on unpooling. I removed the latter in last 
revision without considering your specific example.

Thanks for letting me know, I'll change this behavior so that manipulating 
objects that are in the pool won't have any effect.

Original comment by aurelien.ribon on 19 May 2012 at 7:17

GoogleCodeExporter commented 8 years ago
Fixed in last commit. Tweens and timelines are reset each time they are 
unpooled.

Original comment by aurelien.ribon on 19 May 2012 at 7:25

GoogleCodeExporter commented 8 years ago
Thanks!

I was starting to think it must be that. I sent you a PM on the badlogic forums 
yesterday to that effect. There is still a question of how to safely cancel a 
timeline that may already have completed. It may already have been unpooled and 
in use. One workaround could be to set theuser data of your timeline to a 
private member variable, then check if it still equal to that before 
cancelling. Maybe it would be worth putting in a TweenManager.killKey or 
something, so you can cancel a specific (group of) timeliness and/or 
Tween.calls safely (since killTarget dooesnt work in this case)?

Thanks again for thebawsome lib!

Original comment by felixwatts on 19 May 2012 at 7:42

GoogleCodeExporter commented 8 years ago
I answered that in libgdx forums, check your messages :)

Original comment by aurelien.ribon on 21 May 2012 at 7:11