Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Trouble with a Level Editor Program

  1. #1
    Member Gravity Games's Avatar
    Join Date
    May 2012
    Posts
    152
    Thanks
    6
    Thanked 1 Time in 1 Post

    Default 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:

    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.

    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");
    		}
    	}
    Current Projects (and planned release dates):

    Chomp's Wacky Worlds [???] (PC, Android and Ouya)
    Kyle the Caiman [???] (PC, Android and Ouya)
    KTC: King Crocko's Mystic Maze [???] (PC, Android and Ouya)


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Trouble with a Level Editor Program

    java.lang.StackOverflowError
    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.
    If you don't understand my answer, don't ignore it, ask a question.

  3. The Following User Says Thank You to Norm For This Useful Post:

    Gravity Games (November 16th, 2012)

  4. #3
    Member Gravity Games's Avatar
    Join Date
    May 2012
    Posts
    152
    Thanks
    6
    Thanked 1 Time in 1 Post

    Default 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...
    Current Projects (and planned release dates):

    Chomp's Wacky Worlds [???] (PC, Android and Ouya)
    Kyle the Caiman [???] (PC, Android and Ouya)
    KTC: King Crocko's Mystic Maze [???] (PC, Android and Ouya)

Similar Threads

  1. BlueJ trouble or program trouble (Combining Arraylists)
    By star12345645 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: March 11th, 2012, 12:15 PM
  2. Having trouble with my program, can someone please help?
    By cbutcher0007 in forum What's Wrong With My Code?
    Replies: 4
    Last Post: February 21st, 2012, 12:48 PM
  3. Trouble sending an email from my program
    By java99 in forum Java Networking
    Replies: 5
    Last Post: January 11th, 2012, 11:22 PM
  4. Trouble with Java payroll program
    By Shawn Wray in forum What's Wrong With My Code?
    Replies: 2
    Last Post: January 4th, 2012, 12:57 AM
  5. Need help with a beginning level stock program
    By laughingeyes18 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: November 30th, 2011, 10:31 PM