Why do i get this exception?

45 views
Skip to first unread message

ramzah....@gmail.com

unread,
Nov 1, 2013, 7:16:15 AM11/1/13
to pl...@googlegroups.com
Exception in thread "main" java.lang.IndexOutOfBoundsException: Index: 1, Size: 1
    at java.util.ArrayList.rangeCheck(Unknown Source)
    at java.util.ArrayList.get(Unknown Source)
    at playn.core.gl.GroupLayerGL.render(GroupLayerGL.java:173)
    at playn.core.gl.GroupLayerGL.paint(GroupLayerGL.java:166)
    at playn.core.gl.GroupLayerGL.render(GroupLayerGL.java:173)
    at playn.core.gl.GroupLayerGL.paint(GroupLayerGL.java:166)
    at playn.core.gl.GL20Context.paint(GL20Context.java:71)
    at playn.java.JavaGraphics.paint(JavaGraphics.java:152)
    at playn.java.JavaPlatform.run(JavaPlatform.java:281)
    at playn.core.PlayN.run(PlayN.java:47)

Problem is this only happens when i kill 2 enemies in quick succession on my game, otherwise i never get this exception.. The enemies are rendered inside an immediate layer. I have no idea how to solve this..

Neil White

unread,
Nov 1, 2013, 11:45:28 PM11/1/13
to pl...@googlegroups.com
seems you are trying to read data from an non existent array, check what order you are killing / creating enemies, or perhaps you are confucing the amount of an array with the actual number in the array aka, an array defined as 4 is 0-3, so if you try and hit 5 in that array you are out of bounds cos the 4th element is actually [3]


--
 
---
You received this message because you are subscribed to the Google Groups "PlayN" group.
To unsubscribe from this group and stop receiving emails from it, send an email to playn+un...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Neil White

unread,
Nov 1, 2013, 11:46:10 PM11/1/13
to pl...@googlegroups.com
hit 4 sorry, had my face in this laptop for 13 hours

ramzah....@gmail.com

unread,
Nov 2, 2013, 8:20:11 AM11/2/13
to pl...@googlegroups.com
I don't think i'm making the second mistake, since i have a separate class that adds enemies on the screen with a random timer.
About going out of an array index i don't think it's that either since i'm using iterators and while(iterator.hasNext()) {move enemy, if enemy dies, iterator.remove()} that's all i'm really doing..

Michael Bayne

unread,
Nov 2, 2013, 10:27:37 AM11/2/13
to pl...@googlegroups.com

On Sat, Nov 2, 2013 at 5:20 AM, <ramzah....@gmail.com> wrote:
I don't think i'm making the second mistake, since i have a separate class that adds enemies on the screen with a random timer.

What kind of timer? If you're using java.util.Timer or a separate thread, then you're modifying state from two different threads, leading to race conditions like the one you're seeing. You're also limiting yourself to the Java and Android backends because those are the only ones that support java.util.Timer.

You should either use tripleplay.util.Timer, which works on all platforms and correctly runs entirely on the main PlayN thread, or you should use Platform.invokeLater() from your timer code so that you get back onto the main PlayN thread before you change your game state.

ramzah....@gmail.com

unread,
Nov 2, 2013, 12:21:38 PM11/2/13
to pl...@googlegroups.com
Neither of those, PlayN update() method calls EnemyManager update() method, inside of it i have a variable that starts at random from 0 to 80 and increases every method call, when it reaches 100 it spawns a mob and reset to random amount.

Brigt Vik

unread,
Nov 2, 2013, 3:12:38 PM11/2/13
to pl...@googlegroups.com, ramzah....@gmail.com
What you do sounds proper enough. You could compile an own version of PlayN where you add an extra if statement to the GroupLayerGL class at line 173 (or possibly 166):

if(loopIndex >= referencedArray.length)
{
   int a = 0;
}

You'll obviously need to change the variable names, but this will allow you to set a breakpoint in the PlayN class which only fires when stuff has got screwed up, so you can inspect what's up.

ramzah....@gmail.com

unread,
Nov 2, 2013, 5:14:46 PM11/2/13
to pl...@googlegroups.com, ramzah....@gmail.com
I have no idea how to do that, could you please tell me how or provide me with a step-by-step guide please?
Thanks.

Brigt Vik

unread,
Nov 3, 2013, 3:59:08 AM11/3/13
to pl...@googlegroups.com, ramzah....@gmail.com
Note that I am writing this from memory, which may not be entirely correct or complete.

First, find a proper location for the PlayN code on your local disk. Let's call that PLAYN_HOME from now on.

# mkdir PLAYN_HOME
# cd PLAYN_HOME

Then, fetch the PlayN code from the source.

# git clone http://code.google.com/p/playn

Import to a project in your favourite IDE.

Find the GroupLayerGL.java file and modify it, adding the breakpoint location.

Install your very own version of PlayN into your maven repository

# cd PLAYN_HOME
# mvn install

Open your own game project. You may need to attach the PlayN sources in order to step into those classes (you got those sources in PLAYN_HOME).

Find the GroupLayerGL class and set a breakpoint to the crash location, where you added the if block.

Start your game (in debug mode obviously), and play until you reach the crash condition. Inspect the current data to see if you can spot any clue.

------------

Alternatively, you could create a similar breakpoint in your own game code, if you can properly identify when it happens, and then step down into the PlayN code without having to hack into the PlayN library.

ramzah....@gmail.com

unread,
Nov 4, 2013, 3:26:49 PM11/4/13
to pl...@googlegroups.com, ramzah....@gmail.com
Thanks for all the help, i figured out the problem and fixed it.
The problem was not in the removing of the enemy image on the screen..
In my game when an enemy dies, i create an ImmediateLayer with an explosion sprite animation to make it explode. To animate it i made it so it went thru all the sprite images and then destroy itself when it reaches the last frame, but it seems like immediatelayer runs on a different thread than PlayN.
I fixed it by only drawing from frame 1 of the sprite, to the last one. instead of always draw and destroy only when last frame is drawn.
Thanks again everyone.
Reply all
Reply to author
Forward
0 new messages