JApplet Browser Reload/Refresh

I have a JOGL-based JApplet using GLCanvas that seems to work just fine on first run. However, if you hit refresh in the browser it hangs and you have to close out of the browser and re-open before you can open the applet again. From my experimenting it seems to do with some of the AWT calls I’m making but I haven’t been able to narrow it down much further than that yet. Can someone shed some light on this? I obviously don’t like the idea of my applet killing the browser if someone hits “Refresh”. :o

test cases test cases test cases …

please provide a simple and easy test case, ie
give us the URL of your applet.

would be best, if it uses JNLP … etc …,
so we can easily test it.

thank you

Are you using any static variables/initializers? These might not be reinitialized if you’re in the browser and leave/return or reload (or alternatively, they might be, so don’t count on any particular behaviour).

http://74.208.103.27/splash

It uses the applet-launcher and rendering the UI entirely in JOGL. You’ll notice if you try to reload it crashes. If I set the “separate_jvm” it does solve the problem, but obviously only on u10+. I guess I’m looking for some reading materials on how to better work with applets lifecycle as I’m obviously screwing something up. I’ve got a multi-threading architecture that uses static references so that perhaps is part of the problem, but I don’t believe it is all. I really believe it’s something in AWT that’s actually causing the VM to hang.

Sir, if this is yourr idea of ‘simple’ :slight_smile:
Nice & fast launching demo.

Doesn’t crash here.

Yes, read the Applet’s plugin lifestyle in the javadoc API :),
no really there is nothing more to it - there shall be nothing more.
Otherwise … it’s a bug - of course.

init, start, stop, destroy - that’s it …
Important: init, start and stop may happen as soon as possible.

Just fixed a lot of JOGL[2] spec … kinda same here for GLEventListener:
init, dispose - like applet’s you shall be able to do it again and again.
(forgot the fancy math. name for it).

in case you ‘init’ again … ensure you have no references to ‘dead’ resources,
or even still use them. But you now all this, I guess.
Sorry … couldn’t reproduce it here.

We shall have a test/bug protocol:

  • simple test case
  • sources
  • online testable … if possible or a simple way
  • a recipe how to reproduce the bug
  • spec of the buggy environment: version version version (java, jogl, os, gpu, browser, … and what you had for lunch)

Great stuff …

Sweet stuff … later.

Great applet! (400 fps with mesa gl)

might also help if it is a issue with static fields. (loads each applet in a separate classloader, don't know how it behaves on reloads...)

You guys can refresh it and it works? For me it will not reload a second time.

BTW, this is built using a new framework I’ve been writing that is in early alpha, but is intended to be a next generation UI system in Java to compete with Flex, Silverlight, and JavaFX. It provides an awesome event model, FXG and SVG importing support, Easings, bindings to any UI property, and much more. You’re welcome to see the source code here:
http://jseamless.googlecode.com/svn/framework/branches/2.0/

My biggest problems I’m trying to overcome right now is supporting reloading of the applet, startup times, and performance tuning as I think the performance is rather bad on lower-end hardware. I’ll be posting more about this in the near future, but I’m still pretty new to JOGL and if anyone is interested in helping out I would very much appreciate the assistance. You can see version 1.1 release of jSeamless at http://jseamless.org.

I’ve traced a bit further and found that my GLCanvas is not init()ting, reshape()ing, or display()ing as determined by the GLEventListener after the first load. I’m running on 1.6u12 on Windows Vista and have seen this on other machines as well.

Little bit more digging. I’ve come up with a simple test, but just realized that part of my problem might be that once I realized there was a problem running it in Firefox I switched over to Internet Explorer 8 and have been testing in it since I do all my web browsing in FF. I just tested the following in FF and it works fine, so apparently this specific problem is related to IE 8:

package org.jseamless.test.basic;

import java.applet.Applet;
import java.awt.BorderLayout;

import javax.media.opengl.GL;
import javax.media.opengl.GLAutoDrawable;
import javax.media.opengl.GLCanvas;
import javax.media.opengl.GLEventListener;

import com.sun.opengl.util.Animator;
import com.sun.opengl.util.FPSAnimator;

public class TestBasic extends Applet implements GLEventListener {
	private static final long serialVersionUID = 5605014646241507255L;

	private Animator animator;
	
	public void init() {
		System.out.println("Applet.init()");
		setLayout(new BorderLayout());
		GLCanvas canvas = new GLCanvas();
		canvas.addGLEventListener(this);
		canvas.setSize(getSize());
		add(canvas, BorderLayout.CENTER);
		animator = new FPSAnimator(canvas, 60);
	}
	
	public void start() {
		System.out.println("Applet.start()");
		animator.start();
	}
	
	public void stop() {
		System.out.println("Applet.stop()");
		animator.stop();
	}
	
	public void init(GLAutoDrawable drawable) {
		System.out.println("GLEventListener.init()");
		GL gl = drawable.getGL();

	    gl.glEnable(GL.GL_NORMALIZE);
	}
	
	public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {
		System.out.println("GLEventListener.reshape()");
		GL gl = drawable.getGL();

	    float h = (float)height / (float)width;
	            
	    gl.glMatrixMode(GL.GL_PROJECTION);

	    gl.glLoadIdentity();
	    gl.glFrustum(-1.0f, 1.0f, -h, h, 5.0f, 60.0f);
	    gl.glMatrixMode(GL.GL_MODELVIEW);
	    gl.glLoadIdentity();
	    gl.glTranslatef(0.0f, 0.0f, -40.0f);
	}
	
	public void displayChanged(GLAutoDrawable drawable, boolean modeChanged, boolean deviceChanged) {
	}

	public void display(GLAutoDrawable drawable) {
	}
}

You can test it for yourself at http://download.jseamless.org/basic.html. I’m going to have to switch back to FF to test the original problem, but ideally I’d like even the crazy IE users to be able to reload the applet. :stuck_out_tongue:

An update for anyone that runs into this problem in the future:

I was able to solve my problems in Firefox by making sure not to make static references to things that may become invalid during the disposal of the original applet seeing as by default applets being “reloaded” share the same VM. The second thing I had to do was to flush (renderer.getImage().flush()) and nullify all of my TextureRenderer references to clear memory references to keep from getting OutOfMemoryErrors.

The problem with IE 8 still persists and hopefully someone on the JOGL team sees this and has a solution to properly kill the GL context for recreation, but it may be more than I can hope for to work properly in Internet Explorer. ::slight_smile:

Have you checked, that you implemented the applet lifecycle correctly? Reloading might just call stop() and start() again without destroy() and init() at all.

cylab, the fact that it now works on everything but Internet Explorer leads me to believe that it’s not my problem, but a crazy browser’s fault. :stuck_out_tongue: