LWJGL Forum

Programming => Lightweight Java Gaming Library => Topic started by: Grandmaster B on August 19, 2008, 15:50:37

Title: Applet does not restart
Post by: Grandmaster B on August 19, 2008, 15:50:37
Hi, i finally got my applet running. Problem is when i close the applet and rerun it again in the same instance of the browser the whole thing crashes (FF) or just doesn't work/start (IE).

This is basically the code im using to create the applet (setParent() method):

display_parent = new Canvas();
display_parent.setSize(780,480);
display_parent.setFocusable(true);
display_parent.setIgnoreRepaint(true);
applet.add(display_parent);
Display.setParent(display_parent);
Display.setVSyncEnabled(false);
Display.create();


I tried different things without luck. Any help is appreciated.
Title: Re: Applet does not restart
Post by: kappa on August 19, 2008, 16:26:02
Remember you must destroy the display_parent when you finish with applet or want to restart. This will close the lwjgl display cleanly and prevent it crashing (and taking your browser out). This can be done with applets in destroy().

I'd recommend you look at how its done in the applet gears example

http://java-game-lib.svn.sourceforge.net/viewvc/java-game-lib/trunk/LWJGL/src/java/org/lwjgl/test/applet/GearsApplet.java?view=markup

Notice the slightly weird structure of the applet in that example, the main stuff is run in a seperate thread and display_parent is destroyed when that thread is done. This is done so that whatever happens in the new thread when the applet is closed/restarted display_parent will always be destroyed before it closes/restarts, thus avoiding a crash.
Title: Re: Applet does not restart
Post by: Grandmaster B on August 19, 2008, 16:40:46
Thank you very much! :)