I've been trying to solve this problem by placing System.out.println statements in different parts of the program. Remember you might have to run the applet a few times before it freezes and don't use the retry button to try again. Just refresh the page.
Here's the code again with some small modifications like adding the println statements. I'm sorry I have to post the whole code but I don't really know where the problem is so I post it all. I put bold on all println statements and some lines of code that got to do with what happens when hp reaches 0, theese stop or start threads.
Here is the last lines in console after a freeze. It always ends in Ter1dead:true Ter2dead:true Ter3dead:true Ter4dead:true You can also try the applet yourself and check the console the println statements are there.
Those I took when the applet had freezed.
Help will be appriciated
[ February 08, 2006: Message edited by: Jon Mattson ]
[ February 08, 2006: Message edited by: Jon Mattson ] [ February 08, 2006: Message edited by: Jon Mattson ]
There are a few things which concern me. Why do you have your run methods as synchronized? They should only be called once, so there's no need to have them synchronized. Plus, synchronization causes the JVM to lock objects, which could cause some problems. I stay away from synchronized until I notice deadlocks occuring.
Another is the volatile Thread property. Why? Volatile is used when the property will be changed by an outside source, ie: not in the program. A hardware register changes, like the VBlank bit on a video card, or the address where the hardware timer stores the current time. Those are all volatile.
I don't think those are the problems, but I'd start there.
Sorry haven't been able to post been busy in school.
I uploaded yet another version of the applet. Now I somehow managed to get the retry button work and I removed the volatile and synchronized statements. This freezing problem is annoying cuz it seems to happen pretty randomly. But now there seems to be less of it. Didn't manage to make it freeze in the web browser but it did freeze in Eclipse. I still hope someone could find something in my code that could cause freezing.
Now I'm planning to make a hiscore system to that game which displays the scores on a webpage. I've been searching on google about it but haven't found that much info about it. I read somewhere about someone who used a php page which the applet updated with some command. Could someone lead me to the right direction about this issue? To a tutorial or class I should use. :roll:
pie. tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop