Trouble with a Level Editor Program
Hi, Gravity Games here, and I've been working on a level editor for my game engine. The only problem is that every once in a while, it will freeze up and give me these errors:
Quote:
Exception in thread "Thread-1" java.lang.StackOverflowError
at java.util.HashMap.put(Unknown Source)
at java.util.HashSet.add(Unknown Source)
at sun.awt.AWTAutoShutdown.notifyThreadBusy(Unknown Source)
at java.awt.EventQueue.postEvent(Unknown Source)
at java.awt.EventQueue.postEventPrivate(Unknown Source)
at java.awt.EventQueue.postEvent(Unknown Source)
at javax.swing.RepaintManager.scheduleProcessingRunna ble(Unknown Source)
at javax.swing.RepaintManager.scheduleProcessingRunna ble(Unknown Source)
at javax.swing.RepaintManager.addDirtyRegion0(Unknown Source)
at javax.swing.RepaintManager.addDirtyRegion(Unknown Source)
at javax.swing.JComponent.repaint(Unknown Source)
at java.awt.Component.repaint(Unknown Source)
at com.gravitygamesinteractive.firebreathers.Main.run (Main.java:247)
at com.gravitygamesinteractive.firebreathers.Main.run (Main.java:251)
and after that it just loops the final line over and over. I can't seem to find out whats causing this, though I'm almost certain that its not the run method itself, but one of the methods called by it. The run method calls the tick method of the main object, and that calls the tick method of the level object. Here's the method that I'm suspicious is causing it, but I'm not 100% sure.
Code :
public void editing(){
try{
if(Frame.isMouseLeftDown){
mousex=(Frame.mouse.x+Frame.sx)/16;
mousey=(Frame.mouse.y+Frame.sy)/16;
if(currentobject<255){
tile.add(new Tile(blockcollision,mousex*(16),mousey*16,currentobject));
Frame.isMouseLeftDown=false;
}else{
if(currentobject==257){
sprite.add(new GiantBug(mousex*16,mousey*16,32,32,extra1,257,extra2));
Frame.isMouseLeftDown=false;
}
}
}else if(Frame.isMouseRightDown){
mousex=(Frame.mouse.x+Frame.sx)/16;
mousey=(Frame.mouse.y+Frame.sy)/16;
if(currentobject<=255){
for(int e=0;e<tile.size();e++){
if(tile.get(e).x>Frame.sx-32&&tile.get(e).y>Frame.sy-32&&tile.get(e).x<Frame.sx+Frame.size.width+32&&tile.get(e).y<Frame.sy+Frame.size.height+32){
if(tile.get(e).x>=mousex*16&&tile.get(e).x<=(mousex+1)*16-1){
//tile.get(e).tick();
if(tile.get(e).y>=mousey*16&&tile.get(e).y<=(mousey+1)*16-1){
tile.remove(e);
}
}
}
}
}else if(currentobject>255){
for(int e=0;e<sprite.size();e++){
if(sprite.get(e).x>Frame.sx-32&&sprite.get(e).y>Frame.sy-32&&sprite.get(e).x<Frame.sx+Frame.size.width+32&&sprite.get(e).y<Frame.sy+Frame.size.height+32){
if(sprite.get(e).x>=mousex*16&&sprite.get(e).x<=(mousex+2)*16-1){
//sprite.get(e).tick();
if(sprite.get(e).y>=mousey*16&&sprite.get(e).y<=(mousey+2)*16-1){
sprite.remove(e);
}
}
}
}
}
}
}catch(Exception e){
System.out.println("erroreditingstage");
}
}
Re: Trouble with a Level Editor Program
Quote:
java.lang.StackOverflowError
Quote:
it just loops the final line over and over.
Sounds like a recursive call. Look at the line numbers shown in the trace output to find what method(s) are being called repeatedly.
Re: Trouble with a Level Editor Program
Well, the run method quite obviously calls itself again when its done, should I not be doing that?
EDIT: Well, removed it and apparently its NOT needed to call the run method again, its already a thread. Stupid YouTube tutorials...