dermetfan / java-universal-tween-engine

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

Error in TweenManager.update(int millis) #4

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I'm using Tween Engine extensively in my game and 5.2 causes a weird problem. 
It doesn't appear every time, so I can't provide any specific steps to 
reproduce it.
Here's the stacktrace:

Exception in thread "LWJGL Application" java.lang.IndexOutOfBoundsException: 
Index: 1, Size: 1
    at java.util.ArrayList.RangeCheck(ArrayList.java:547)
    at java.util.ArrayList.get(ArrayList.java:322)
    at aurelienribon.tweenengine.TweenManager.update(TweenManager.java:196)

I think the problem is that you're declaring n=tweens.size() inside the for 
loop. I know it's in the initialization step and SHOULD be executed once, but 
it seems it's not the case. Putting this before the loop fixed the problem.
I changed:

    public final void update(int deltaMillis) {
        for (int i=0, n = tweens.size(); i<n; i++) {

to:

    public final void update(int deltaMillis) {
        int n = tweens.size();
        for (int i=0; i<n; i++) {

Original issue reported on code.google.com by Thotep on 9 Nov 2011 at 10:16

GoogleCodeExporter commented 9 years ago
That's quite strange, the two versions are the same and the second one 
shouldn't correct the issue. Moreover, the line 196 in TweenManager corresponds 
to "i -= 1;" and not to the get() call.

However, I spotted a bug in the engine. It shouldn't affect you but I would 
appreciate if you could tell me if the latest revision fixes your bug or not. I 
packaged the revision in the following jar:

http://dl.dropbox.com/u/16375762/tween-engine-api-5.2.1.zip

Original comment by aurelien.ribon on 10 Nov 2011 at 1:03

GoogleCodeExporter commented 9 years ago
Thanks, I tried 5.2.1, but it crashes either:

Exception in thread "LWJGL Application" java.lang.IndexOutOfBoundsException: 
Index: 12, Size: 2
    at java.util.ArrayList.RangeCheck(ArrayList.java:547)
    at java.util.ArrayList.get(ArrayList.java:322)
    at aurelienribon.tweenengine.TweenManager.update(TweenManager.java:178)

About the line number: I played around with the code, that's why it didn't 
match yours. The one above does.
I know these two versions _should_ be the same... But this change certainly 
doesn't break anything in your function, and if it fixes this weird problem, 
maybe you could change it in your code as well? :)

Original comment by Thotep on 10 Nov 2011 at 8:07

GoogleCodeExporter commented 9 years ago
I changed the code to the previous working version. The list size is checked on 
each pass. Can you tell me if it fixes your issue ?

http://dl.dropbox.com/u/16375762/tween-engine-api-5.2.1.zip

Anyway, sorry about the inconvenience, couldn't have imagined such code would 
lead to errors...

Original comment by aurelien.ribon on 11 Nov 2011 at 1:29

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
Sorry for the delay. This version seems to have fixed it. Thanks!
Is it the same as the official 5.2.1?

Original comment by Thotep on 16 Nov 2011 at 7:41

GoogleCodeExporter commented 9 years ago
Thanks :)
It thought it was the case, so released 5.2.1 anyway (it is the same yes) :D

Original comment by aurelien.ribon on 16 Nov 2011 at 8:36