CollidedWith stack overflow

6 views
Skip to first unread message

Kevin Moran

unread,
Feb 9, 2012, 2:04:15 AM2/9/12
to android-progr...@googlegroups.com
I'm getting the same stack overflow as other's have had but calling super didn't do anything

public void CollidedWith(Sprite other) {
super.CollidedWith(other);
explosion = new ExplosionSprite(myCanvas);
explosion.Picture("explosion.png");
explosion.Initialize();
explosion.MoveTo(this.X(), this.Y());
}

02-08 22:58:24.230: E/AndroidRuntime(1077): at com.google.devtools.simple.runtime.components.android.ImageSprite.Picture(ImageSprite.java:159)
02-08 22:58:24.230: E/AndroidRuntime(1077): at com.shooter.Project2Activity$AndroidSprite.CollidedWith(Project2Activity.java:168)
02-08 22:58:24.230: E/AndroidRuntime(1077): at com.google.devtools.simple.runtime.components.android.Canvas.findSpriteCollisions(Canvas.java:547)
02-08 22:58:24.230: E/AndroidRuntime(1077): at com.google.devtools.simple.runtime.components.android.Canvas.registerChange(Canvas.java:505)
02-08 22:58:24.230: E/AndroidRuntime(1077): at com.google.devtools.simple.runtime.components.android.Sprite.Initialize(Sprite.java:84)
02-08 22:58:24.230: E/AndroidRuntime(1077): at com.shooter.Project2Activity$AndroidSprite.CollidedWith(Project2Activity.java:169)
02-08 22:58:24.230: E/AndroidRuntime(1077): at com.google.devtools.simple.runtime.components.android.Canvas.findSpriteCollisions(Canvas.java:547)
02-08 22:58:24.230: E/AndroidRuntime(1077): at com.google.devtools.simple.runtime.components.android.Canvas.registerChange(Canvas.java:505)
02-08 22:58:24.230: E/AndroidRuntime(1077): at com.google.devtools.simple.runtime.components.android.Sprite.Initialize(Sprite.java:84)
02-08 22:58:24.230: E/AndroidRuntime(1077): at com.shooter.Project2Activity$AndroidSprite.CollidedWith(Project2Activity.java:169)

Any ideas?

Kevin

David W Wolber

unread,
Feb 9, 2012, 11:51:30 AM2/9/12
to android-progr...@googlegroups.com
Hi, sorry, went to bed. You may have figured this out but one idea I have is that each of your new explosion imagesprites might be colliding with the object in a never-ending loop. So not the same two objects colliding but all your new ones.

You can check other to make sure its the one your care about.

Dave

Kevin Moran

unread,
Feb 9, 2012, 12:09:06 PM2/9/12
to android-progr...@googlegroups.com
Unfortunately I couldn't figure it out. Isn't super.CollidedWith supposed to prevent it from infinitely colliding? 

For example, if there is only one enemy on screen, and only on bullet fired, it will still crash even if the method was only:

public void CollidedWith(Sprite other) {
super.CollidedWith(other);
explosion = new ExplosionSprite(myCanvas);
}

(this method is the collidedWith for the enemy by the way)

So the only collision happening is the bullet with the enemy. Not sure how to fix it.. The way the program is designed, we do not care about how many objects are on screen because each object takes care of it's own colliding. This makes manually doing the collision detection very difficult as new objects are constantly being added and old objects are constantly being removed. I'll come in to your office this morning if you are around.

Kevin

David W Wolber

unread,
Feb 9, 2012, 12:24:47 PM2/9/12
to android-progr...@googlegroups.com
Hi Kevin. I'm here if you want to come by but I have class at 9:45.

super.collidedWith does register the two objects (enemy and bullet) as colliding so the event isn't triggered again (until the same two objects are no longer colliding then collide again).

But I think your explosion objects are being created and colliding with enemy (or bullet, whoever this is) which is in turn creating a new explosion object, and so on...

not sure, but this is what I think is going on, and I think an if, inside the CollidedWith, checking which objects are colliding will handle it.

Dave

Kevin Moran

unread,
Feb 9, 2012, 12:33:01 PM2/9/12
to android-progr...@googlegroups.com
Oh I think I see what you're saying. I'll give that a shot.

Thanks,
Kevin

David W Wolber

unread,
Feb 9, 2012, 12:38:30 PM2/9/12
to android-progr...@googlegroups.com
cool, and cross your fingers,

Dave
Reply all
Reply to author
Forward
0 new messages