Sign in to follow this  

stackOverflowError help plz!

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
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 this post


Link to post
Share on other sites
Guest Anonymous Poster
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 this post


Link to post
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
Exception in thread "main" java.lang.StackOverflowError
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 this post


Link to post
Share on other sites
Guest Anonymous Poster
Quote:
Original post by BangorRipper
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
Exception in thread "main" java.lang.StackOverflowError
Press 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 this post


Link to post
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 this post


Link to post
Share on other sites

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

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this