Java-Gaming.org
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
Featured games (78)
games approved by the League of Dukes
Games in Showcase (407)
games submitted by our members
Games in WIP (293)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Problems cleaning up an applet  (Read 1016 times)
0 Members and 1 Guest are viewing this topic.
Offline Serethos

Junior Member




Java games rock!


« Posted 2004-02-22 14:30:37 »

i have an applet using one thread for drawing graphics.
the problem is when i use appletviewer with console window in background and i close the applet window, the onsole frame seems to lock for a while.


the code:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
        public void start()
      {
            if (runner == null)
            {
                  runner = new Thread(this);
                  runner.start();
            }
            System.out.println("Applet : Start");
      }

      public void stop()
      {
            System.out.println("applet stop");
            runner = null;
      }
     
     
      public void destroy()
        {
             offscreen.dispose();
             System.out.println("destroyed");
         }


im in sorrow that the thread doesnt get destroyed properly.
Offline tom
« Reply #1 - Posted 2004-02-22 15:14:09 »

Do you exit your run() function when runner is set to null? You must do something like this:

1  
2  
3  
4  
5  
public void run() {
   // exit game loop when stop() is called.
  while (runner != null) {
   }
}


When you exit the run() function the thread will stop.

Offline Serethos

Junior Member




Java games rock!


« Reply #2 - Posted 2004-02-22 16:09:51 »

i added the code line, but finishing the applet still seems to take to long.  its only a matter of ~10 sec. but if i run a applet with no extra thread it clears up immediately
Games published by our own members! Check 'em out!
Try the Free Demo of Revenge of the Titans
Offline tom
« Reply #3 - Posted 2004-02-22 16:47:18 »

The only other thing I can think of is seting runner to be a daemon thread:
1  
2  
3  
runner = new Thread(this); 
runner.setDaemon(true);
runner.start();


From setDaemon javadoc: "The Java Virtual Machine exits when the only threads running are all daemon threads."

Offline nonnus29

Senior Member




Giving Java a second chance after ludumdare fiasco


« Reply #4 - Posted 2004-02-22 19:59:47 »

I always call stop() on the animation thread and I've never seen the problem you describe.

1  
2  
3  
4  
5  
6  
7  
public void stop ()  {
            if (animation != null)  {
                  animation.stop();
                  animation=null;
            }
           
}
Offline swpalmer

JGO Coder




Where's the Kaboom?


« Reply #5 - Posted 2004-02-22 20:10:02 »

Quote
I always call stop() on the animation thread

tsk... tsk...

Using deprecated methods... sigh..

You should interrupt the animation thread and let it exit gracefully.
I usually have something like this for my animation loop:

1  
2  
3  
4  
5  
6  
7  
8  
9  
try {
  while( !Thread.interrupted() ) {
    doStuff()
    Thread.sleep( x );
  }
}
catch(InterruptedException e) {
  // just exit
}


In the applet stop() method:
1  
2  
animThread.interrupt();
animThread.join();

Offline nonnus29

Senior Member




Giving Java a second chance after ludumdare fiasco


« Reply #6 - Posted 2004-02-23 03:57:07 »

Quote
Using deprecated methods... sigh..


Oops, I didn't know stop() was deprecated;  I wondered why I kept getting those deprecated warnings, but didn't care enough to compile with the correct flag to see what it was  :-/ .  Yes, I'm lazy like that....
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
 
Get high quality music tracks for your game!

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

The invasion has landed! On Mars! And you're there to beat 'em!
cubemaster21 (92 views)
2013-05-17 21:29:12

alaslipknot (100 views)
2013-05-16 21:24:48

gouessej (130 views)
2013-05-16 00:53:38

gouessej (125 views)
2013-05-16 00:17:58

theagentd (136 views)
2013-05-15 15:01:13

theagentd (124 views)
2013-05-15 15:00:54

StreetDoggy (165 views)
2013-05-14 15:56:26

kutucuk (187 views)
2013-05-12 17:10:36

kutucuk (190 views)
2013-05-12 15:36:09

UnluckyDevil (197 views)
2013-05-12 05:09:57
Complex number cookbook
by Roquen
2013-04-24 12:47:31

2D Dynamic Lighting
by Oskuro
2013-04-17 16:46:12

2D Dynamic Lighting
by Oskuro
2013-04-17 16:45:57

2D Dynamic Lighting
by Oskuro
2013-04-17 16:23:20

Noise (bandpassed white)
by Roquen
2013-04-05 17:36:01

Noise (bandpassed white)
by Roquen
2013-04-03 16:17:38

Java Data structures
by Roquen
2013-03-29 13:21:12

Topic Request
by kutucuk
2013-03-22 21:42:01
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!
Page created in 0.15 seconds with 20 queries.