Applet takes long to exit

Hi there! First post (of many to come, I hope).

I’m trying to learn how to make games using Java. I moved from C++ to Java in order to 1) focus on learning game-specific software design, 2) place my games online using applets.

I’ve made a basic applet using LWJGL tutorial (found here). When debugging I’ve noticed that it takes around 5-10 seconds to end execution once I’ve closed the applet window. I think this behavior is not from my code since the LWJGL gear example (found here) does the same.

Am I doing something wrong? I feel uncomfortable knowing that maybe I’m wasting resources of the browser keeping that working when it has finished. Is it just paranoia coming from my C++ past?

Thanks in advance!

 if <code>al_debug</code> is true the applet will load and extract resources with a delay, to be able to see the loader process.

Check this.

This is probably not the problem, but it’s also worth noting that the Applet JVM usually doesn’t shut down right after you close the browser tab (if run in a browser)…

  • Scarzzurs

Thanks for your answers.

@pitbuller: I believe that flag is for the AppletLoader, which I’m not using.
@Scarzzurs: I don’t run the applet in a browser, but in the Eclipse IDE.

I’ll try to give more information.

I run the applet using the Eclipse IDE. As the applet starts, I see in the debug view the main threads running. When I close the applet window I see that the game thread stops running because 1) I stop watching the FPS debug information I throw to the console, 2) going step by step I see the game loop ends, finishing the run() function of the thread, and 3) after that it passes a gameThread.join() statement. I believe that will assure that the game thread is over. However I still some threads running that belong to the CustomApplet (derivated from Applet class) I made.

I’m pretty sure it’s not something I did wrong in CustomApplet because I see the same behavior when running in Eclipse the Gears applet that LWJGL provides (not the web applet that actually displays the gears).

Thanks again and I hope now it’s clearer!

If your game loop ends, then all is fine. It’s just your paranoia ;D

The link runs and closes down just fine, for me, when viewed via my browser. (Takes maybe about a second for the Java Console to also disappear.) Eclipse may be a bit sluggish in comparison, since it is an emulation.

In general, you write “stop()” and “destroy()” methods if you want to take explicit control of how your Applet closes itself down.

http://docs.oracle.com/javase/tutorial/deployment/applet/lifeCycle.html

There’s nothing really he can do in stop/destroy that can cause a “faster” shutdown. I still say it’s paranoia. Write a freaking game already!! ;D

I agree with ra4king. As long as it IS shutting down, why worry about the few seconds it takes to do so. Don’t worry about optimizing everything until the game is playable start to finish. Then make it better… or release it and carry on to the next game, knowing what to do and what not to do… Otherwise you’ll end up like me - It’ll probably be a year before my game is done, I can only hope I still feel like writing this game in 6 months from now.

I think I got through the denial phase of my paranoia already. Thanks folks! :smiley:

I was worried about being rude by uploading a inefficient applet. I didn’t want to give a wrong impression in my #LD48 game, though I think there are more pressing problems in my games (for instance, I have never made a game, which I think it’s a great problem D:).

I’ll focus on making games now on, I won’t let my paranoia prevent me from success. Thanks!

Kitties FTW!

Kittens for #LD48!!! :smiley: