From d0f91a8ed17fbb1a7b56511c4e53a29e576f01af Mon Sep 17 00:00:00 2001
From: Sven Gothel <sgothel@jausoft.com>
Date: Thu, 8 Nov 2012 18:07:19 +0100
Subject: Fix GLAutoDrawable.dispose(): Dispose drawable even w/o context;
 JAWTWindow.lockSurface(): Check AWT component's native peer

- Fix GLAutoDrawable.dispose(): Dispose drawable even w/o context
  - It is possible to have the GLContext not being created (not made current),
    so drawable shall be disposed independent.

  - Merge Runnable 'postDisposeOnEDTAction' to dispose Runnable for clarity

  - GLDrawableHelper: Split disposeGL from invokeGLImpl for clarity

- JAWTWindow.lockSurface(): Check AWT component's native peer
  - W/o a native peer (!isDisplayable()), JAWT locking cannot succeed.

  - On OSX OpenJDK 1.7, attempting to JAWT lock a peer-less component crashes the VM

  - MacOSXJAWTWindow.lockSurfaceImpl(): Remove redundant null checks
---
 .../classes/javax/media/opengl/awt/GLJPanel.java   | 29 +++++++++++++---------
 1 file changed, 17 insertions(+), 12 deletions(-)

(limited to 'src/jogl/classes/javax/media/opengl/awt/GLJPanel.java')

diff --git a/src/jogl/classes/javax/media/opengl/awt/GLJPanel.java b/src/jogl/classes/javax/media/opengl/awt/GLJPanel.java
index 58b1baa65..dcfc1f0dd 100644
--- a/src/jogl/classes/javax/media/opengl/awt/GLJPanel.java
+++ b/src/jogl/classes/javax/media/opengl/awt/GLJPanel.java
@@ -757,21 +757,26 @@ public class GLJPanel extends JPanel implements AWTGLAutoDrawable, WindowClosing
     return "AWT-GLJPanel[ "+((null!=backend)?backend.getDrawable().getClass().getName():"null-drawable")+"]";
   }
 
-  private final Runnable postDisposeAction = new Runnable() {
-      @Override
-      public void run() {
-          if (backend != null && !backend.isUsingOwnThreadManagment()) {
-              backend.destroy();
-              backend = null;
-              isInitialized = false;
-          }
-      }
-  };
-
   private final Runnable disposeAction = new Runnable() {
     @Override
     public void run() {
-      helper.disposeGL(GLJPanel.this, backend.getDrawable(), backend.getContext(), postDisposeAction);
+        if ( null != backend ) {
+            final GLContext _context = backend.getContext();
+            if( null != _context && _context.isCreated() ) {
+                // Catch dispose GLExceptions by GLEventListener, just 'print' them
+                // so we can continue with the destruction.
+                try {
+                    helper.disposeGL(GLJPanel.this, _context);
+                } catch (GLException gle) {
+                    gle.printStackTrace();
+                }
+            }
+            if ( !backend.isUsingOwnThreadManagment() ) {
+                backend.destroy();
+                backend = null;
+                isInitialized = false;
+            }
+        }
     }
   };
 
-- 
cgit v1.2.3