Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding new tweens in callback functions is not allowed? #9

Closed
playif opened this issue Aug 11, 2014 · 5 comments
Closed

Adding new tweens in callback functions is not allowed? #9

playif opened this issue Aug 11, 2014 · 5 comments
Labels

Comments

@playif
Copy link

playif commented Aug 11, 2014

I try to add some extra tweens in a callback function (i.e., when a tween completed).
However, since the other updating tweens occupy the _objects list in a forEach function, modifying the _object is not allowed.
Maybe you can add a new list (for those toBeAddedTweens), and pull the new tweens into _objects in the right timing?

@xaguzman
Copy link
Owner

Usually, how I have handled this is invoking either Timeline.createSequence() or Tween.to to create a totally new tween, have never seen an issue with it.

Are you trying to add tweens to an already existing timeline?

@playif
Copy link
Author

playif commented Aug 11, 2014

Are you trying to add tweens to an already existing timeline?

No. Do you add new tweens in another tween's callback function?

@playif
Copy link
Author

playif commented Aug 11, 2014

I made a simple reproduction by your simple_tween.dart example
Just change

    Tween.to(pos, VectorAccessor.XY, 1)
      ..delay = 0.3
      ..targetValues = [x, y]
      ..start(_tweenManager);

to

Tween.to(pos, VectorAccessor.XY, 1)
      ..delay = 0.3
      ..targetValues = [x, y]

      ..setCallback((int type, BaseTween source) {
      Tween.to(pos, VectorAccessor.XY, 2)
        ..delay = 0.3
        ..targetValues = [x, y]
        ..start(_tweenManager);
    })
      ..start(_tweenManager);

And you will get the error:
Uncaught Error: Concurrent modification during iteration: Instance(length:2) of '_GrowableList'.
Stack Trace:
#0 List.forEach (dart:core-patch/growable_array.dart:228)
#1 TweenManager.update (package:tweenengine/src/tween_manager.dart:99:25)
#2 SimpleTween.render (http://localhost:60000/tween-engine-dart-master/example/screens/simple_tween.dart:43:25)
#3 render (http://localhost:60000/tween-engine-dart-master/example/example.dart:63:23)
#4 _rootRunUnary (dart:async/zone.dart:730)
#5 _RootZone.runUnary (dart:async/zone.dart:864)
#6 _Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:488)
#7 _Future._propagateToListeners (dart:async/future_impl.dart:571)
#8 _Future._complete (dart:async/future_impl.dart:317)
#9 _SyncCompleter.complete (dart:async/future_impl.dart:44)
#10 Window.animationFrame. (dart:html:29269)

Exception: Concurrent modification during iteration: Instance(length:2) of '_GrowableList'.

@xaguzman xaguzman added the bug label Aug 11, 2014
@xaguzman
Copy link
Owner

will look into it as soon as I can

@xaguzman
Copy link
Owner

fixed. Avoided applying the suggested fix to avoid allocating more lists into memory.
changing the foreach for a good old for fixed the issue

This will be up for for next version

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants