Sign in to follow this  

[java] java 1.5 freezing up. No error. Help

This topic is 4734 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 i have hit quite a big snag. I just implemented tile based collision and out of nowhere my program just freezes after within 20 seconds. Time varies. It freezes sooner with more enemies. I cant see any reason why this should happen.
public void move()
{	//System.out.println("1");
										
	audio = SoundFactory.sounds.get(soundIndex);							
	animIndex = (int)(Math.random()*3);								
							
	if(targetZDir==0&&targetXDir==0)
	{
		tempX =- posAndRot.x + GraphicsPanel.p.posAndRot.x; 									
		 tempZ =- posAndRot.z + GraphicsPanel.p.posAndRot.z; 						
	}
	else
	{
		tempX =targetXDir; 								
		 tempZ =targetZDir; 					
	}
							
	if(animIndex==0&&lastIndex!=0&&Math.abs(tempX)+Math.abs(tempZ)<=256)
	{							
		playSound(audio[1]);																													
	}									
								
		lastIndex = animIndex;	
	//	System.out.println("2");
	if(Math.abs(tempZ)>=Math.abs(tempX))
	{
		if(!moveZ())
		{
			if(!moveX())
			{
				tempX=-tempX;
				moveX();
			}										
		}					
	}
	else if(Math.abs(tempZ)<Math.abs(tempX))
	{
		if(!moveX())
		{
			if(!moveZ())
			{
				tempZ=-tempZ;
				moveZ();
			}										
		}											
	}	
	//	System.out.println("5");															
}

public boolean moveZ()
{
	
	int sign = (int)(Math.signum(tempZ));
	if(GraphicsPanel.map[(xPos)>>1][(zPos+sign)>>1].bBlockingActors)
	return false;	
	int startPitch=posAndRot.pitch;
																	
	if(tempZ<0&&posAndRot.pitch!=2)
	{
		targetZDir = tempZ;
		if(arrayIndex==0)
		{
			posAndRot.pitch++;											
		}
		else																			
			posAndRot.pitch=2;
		return true;
	}
	else if(tempZ>0&&posAndRot.pitch!=0)
	{
		targetZDir = tempZ;
		if(arrayIndex==0)
		{
			posAndRot.pitch--;											
		}
		else																			
			posAndRot.pitch=0;
		return true;
	}
	if(Math.abs(tempX)<=33&&Math.abs(tempZ)<=97)
	{
		targetZDir = 0;
		targetXDir = 0;			
		return true;
	}										
	//	System.out.println("3");																						
	//	int indexOf = pawns.indexOf(m)+sign;										
										
	if(null==links[sign+1])//indexOf<0||indexOf>=pawns.size())
	{
		posAndRot.z+=sign<<6;//add(inc);
		zPos+=sign;												
		playSound(audio[0]); 
		targetZDir = 0; 
		targetXDir = 0;
		return true;
	}
	else
	{									
		Monster p = links[sign+1];//pawns.get(indexOf);
												
		if(Math.abs(p.zPos-zPos)>1)
		{			
			//Vector3D inc = new Vector3D(0,0,sign<<6);													
			posAndRot.z+=sign<<6;//add(inc);
			zPos+=sign;																			
			playSound(audio[0]); 
			targetZDir = 0;
			targetXDir = 0;
			return true; 
		}	
	}
		posAndRot.pitch=startPitch;
		return false;										
}




the moveX method is very similar to the moveZ method. Nothing unusual in it. I do have alot of unchecked operations because i moved from 1.4.2. I do a sort of all the enemies before i move them all. They move once every 2 seconds. It still freezes if i remove the sort. I am not using threads. I have a timeListener. [Edited by - Riviera Kid on December 30, 2004 8:23:51 AM]

Share this post


Link to post
Share on other sites
Riviera kid, you don't give enough information for me to be able to find the culprint. I think that the error won't be in the part you posted though, as there are no loops, whiles or recursive functions. Why do you think that the error is in here? Also, have you tried to run the program with all the sound stuff commented out? Java's sound utilities are very buggy! I remember that I couldn't even close a Java program the normal way after playing a simple sound...

If you want better help, post the full source (preferably in zip if there are more classes)

Good luck,
Bas

Share this post


Link to post
Share on other sites
Posting full source is the worst thing he could do. Nobody would read through it.

Do you have a debugger? Run it until it freezes, break, and start stepping through the code to see where it's looping.

Share this post


Link to post
Share on other sites
If you're running in an IDE, run the same program outside it to verify that the issue still occurs.

Do a thread dump when the program freezes. You say you're not using threads, but *all* Java programs use multiple threads, so there still may be deadlock. More likely, you're in a tight loop (if so, your CPU load should be near 100%).

To do a thread dump under any flavor of Linux or Unix, either do a CTRL-\ in the shell window you ran from or send SIGQUIT to the process ('pkill -QUIT java' should work on everything but OS X).

To do a thread dump under Windows, do a CTRL-Break in the shell window you ran from. If you ran from a shortcut icon under Windows, you're SOL ... Windows doesn't have (to the best of my knowledge) an analog of 'kill' or 'pkill'.

The thread dump will show you the call stack for each thread. You should recognise some of your methods in the main thread of execution. If there is deadlock, newer (1.4+, IIRC) JVMs will say so right in the trace. If everything looks fine, take several thread dumps in a row ... if the execution point is the same (and not in wait()), you should figure out why that point in the code is being run so often.

Another option would be to put printlns in your main game loop so you can watch the progress. Redirect the output to a file, then, when the app hangs, go look a the last part of the file to see if anything odd occured.

A debugger (try JSwat for a free one if you're not using an IDE) could be helpfull as well ... put a break-point at the top of your game loop. Step through the loop once to see if the path of execution matches your understanding of what you wrote. Then disable the breakpoint and play for about half the time it takes to get your hang. Reenable the breakpoint and again step through your game loop to see if anything has changed. Once the app hangs, you may or may not be able to break in (depending upon your debugger), but if you can, you could check each thread of execution and see where it is running. Perhaps you'll be able to find the bug that way.

Share this post


Link to post
Share on other sites
Quote:
Quote:
Riviera kid, you don't give enough information for me to be able to find the culprint.


Funny you say this no responses? From amount of infromation that you gave, this is a really reasonable answer.

They also asked you what happened when you disabled sound, if you tried to localize a method called just before freeze, and if you used a debugger, you didn't answer them.

By freeze you ment totaly locking up your computer, or just your game ceased to be responsive? (I remmember I was forced to reboot a Linux when I played with the sound server.)

From the forum he posted another help request. Don't be so inpatient.

Share this post


Link to post
Share on other sites
Quote:
Original post by C-Junkie
Posting full source is the worst thing he could do. Nobody would read through it.

Do you have a debugger? Run it until it freezes, break, and start stepping through the code to see where it's looping.


Well C-junkie, I would have been able to test it for myself to see what happens. I find that very important, especially in Java where not only the code, but also the JVM could be at fault. I only use Java for testing stuff quickly, imho it's not a very good programming language in other respects. I preferred qbasic ;)

Share this post


Link to post
Share on other sites

This topic is 4734 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