# stackOverflowError help plz!

This topic is 4799 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

hi guys, happy new year to you all. just trying to load my ship model after i have loaded all of my alien models in space invaders using the same method but in a different class but i'm getting a stackOverflowError. Now is there some way that i am supposed to dispose of the stack after i have finished loadiong my aliens or something. below is a portion of the code that i am using in both the alien class and the ship class to store the models:- float[] floatCoords = new float[coords.size()]; for (int x = 0;x<coords.size();x++) { floatCoords[x] = Float.parseFloat((String) coords.elementAt(x)); } shipData = BufferUtils.createFloatBuffer(coords.size()); shipData.put(floatCoords); shipData.flip(); should i maybe call it floatCoords1 in the ship class or something???!! thanks everyone :)

##### Share on other sites
it could be this line
for (int x = 0;x<coords.size();x++)
try
for (unsigned long x = 0;x<coords.size();x++)

If coords.size() is larger than what an integer can take the whole things goes pooey.

##### Share on other sites
lc_overlord: Thats Java code, so theres no such thing as 'unsigned long'. :)

BangorRipper: Stack overflow in Java almost always means you've got yourself jammed into infinite recursion in some way, since no actual objects get created on the stack (unlike C++). Equally, you never have to worry about cleaning up the stack either.

The code you posted doesn't look like the curprit. Post the entire stack error message (and stack trace with it) and the code it occured from.

OT.

##### Share on other sites
here is the end of the trace writes and the error:-
xAlien = 20.0, yAlien = 0.0, zAlien = 3.0
xAlien = 20.0, yAlien = 0.0, zAlien = 6.0
xAlien = 24.0, yAlien = 0.0, zAlien = 0.0
xAlien = 24.0, yAlien = 0.0, zAlien = 3.0
xAlien = 24.0, yAlien = 0.0, zAlien = 6.0
xShip = -1.0, yShip = 0.0, zShip = 10.0
Press any key to continue...

here is the code that seems to be the problem:-
/**
* Render a collection of aliens to the screen using the GL commands
* and the buffer we've read from the RAW file.
*/
private void renderShip()
{
if (shipIsAlive) {
GL11.glPushMatrix();
GL11.glTranslatef(xShip,yShip,zShip); //move forward
System.out.println("hello");
renderShip();
GL11.glPopMatrix();
}
}

if i put a trace write in here i see a list of hello's nad then the eroor, if i put the hello after the renderShip() then no hello's are displayed
hope someone can spot the problem now
thanks

##### Share on other sites
Quote:
 Original post by BangorRipperhere is the end of the trace writes and the error:-xAlien = 20.0, yAlien = 0.0, zAlien = 3.0xAlien = 20.0, yAlien = 0.0, zAlien = 6.0xAlien = 24.0, yAlien = 0.0, zAlien = 0.0xAlien = 24.0, yAlien = 0.0, zAlien = 3.0xAlien = 24.0, yAlien = 0.0, zAlien = 6.0xShip = -1.0, yShip = 0.0, zShip = 10.0Exception in thread "main" java.lang.StackOverflowErrorPress any key to continue...

You still haven't posted the proper stack trace - thats the one with the list of methods called (and line numbers) when the exception happened. That should appear just before the "Press any key" text. If it doesn't, then you've got a whacking great big try...catch(Exception) block around your code (doing nothing!) which is just plain wrong.

Fortunatly its obvious from your code whats wrong. I've already given you the hint you need (infinite recursion!) if you still can't figure out whats wrong with your code then you're beyond help.

OT.

##### Share on other sites
You have an infinite recursive call for any ships that are still alive. Try following the program flow through yourself on paper. Any time you have a recursive method you must have a base case. In this case I can't see why you are using recursion. Why are you calling renderShip from within itself? What are you trying to achieve?

(Just to be clear, the following is the line at fault:)
/*** Render a collection of aliens to the screen using the GL commands* and the buffer we've read from the RAW file.*/private void renderShip() {	if (shipIsAlive)	{		GL11.glPushMatrix();		GL11.glTranslatef(xShip,yShip,zShip); //move forward		System.out.println("hello");		renderShip();		GL11.glPopMatrix();	}}

Enigma

##### Share on other sites
thanks for the replies guys, not what i thought though!
i wasnt meant to call the same method again, i was meant to call a different method and not the same one, thanks anyway :)