From ffb098e3eed864346f1bd9f53021b17f9148da49 Mon Sep 17 00:00:00 2001 From: Kenneth Russel Date: Fri, 9 Sep 2005 07:08:45 +0000 Subject: Refactored demos to mostly subclass common Demo superclass providing shutdown capabilities. Moved DemoListener to demos.common package. Added ManipManager removal code to demos using manipulators or ExaminerViewer to fix memory leak when run in JRefract harness. Added workaround for another seeming memory leak when run under current JDK 1.6 due to java.awt.Component now being finalizable and keeping data alive longer than previously. Made ManipManager.unregisterWindow more lenient with respect to null or invalid arguments. git-svn-id: file:///usr/local/projects/SUN/JOGL/git-svn/../svn-server-sync/jogl-demos/branches/JSR-231@122 3298f667-5e0e-4b4a-8ed4-a3559d26a5f4 --- .../ProceduralTexturePhysics.java | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) (limited to 'src/demos/proceduralTexturePhysics/ProceduralTexturePhysics.java') diff --git a/src/demos/proceduralTexturePhysics/ProceduralTexturePhysics.java b/src/demos/proceduralTexturePhysics/ProceduralTexturePhysics.java index b1d52c5..6fbab29 100644 --- a/src/demos/proceduralTexturePhysics/ProceduralTexturePhysics.java +++ b/src/demos/proceduralTexturePhysics/ProceduralTexturePhysics.java @@ -39,6 +39,7 @@ import javax.swing.*; import javax.media.opengl.*; import com.sun.opengl.utils.*; +import demos.common.*; import demos.util.*; import gleem.*; import gleem.linalg.*; @@ -57,7 +58,7 @@ import gleem.linalg.*; * */ -public class ProceduralTexturePhysics implements GLEventListener { +public class ProceduralTexturePhysics extends Demo { public static void main(String[] args) { GLCanvas canvas = GLDrawableFactory.getFactory().createGLCanvas(new GLCapabilities()); ProceduralTexturePhysics demo = new ProceduralTexturePhysics(); @@ -88,19 +89,20 @@ public class ProceduralTexturePhysics implements GLEventListener { animator.start(); } - public void setDemoListener(DemoListener listener) { - demoListener = listener; - } - //---------------------------------------------------------------------- // Internals only below this point // - private DemoListener demoListener; + public void shutdownDemo() { + ManipManager.getManipManager().unregisterWindow(drawable); + super.shutdownDemo(); + } + private volatile boolean drawing; private volatile int mousePosX; private volatile int mousePosY; + private GLAutoDrawable drawable; private Water water = new Water(); private volatile ExaminerViewer viewer; private boolean[] b = new boolean[256]; @@ -151,6 +153,7 @@ public class ProceduralTexturePhysics implements GLEventListener { // Register the window with the ManipManager ManipManager manager = ManipManager.getManipManager(); manager.registerWindow(drawable); + this.drawable = drawable; viewer = new ExaminerViewer(MouseButtonHelper.numMouseButtons()); viewer.setAutoRedrawMode(false); @@ -248,7 +251,7 @@ public class ProceduralTexturePhysics implements GLEventListener { if (!gl.isExtensionAvailable(extensionName)) { String message = "Unable to initialize " + extensionName + " OpenGL extension"; JOptionPane.showMessageDialog(null, message, "Unavailable extension", JOptionPane.ERROR_MESSAGE); - demoListener.shutdownDemo(); + shutdownDemo(); } } @@ -258,7 +261,7 @@ public class ProceduralTexturePhysics implements GLEventListener { switch (k) { case 27: case 'q': - demoListener.shutdownDemo(); + shutdownDemo(); break; case 'w': water.enableWireframe(getFlag('w')); -- cgit v1.2.3