Catch remaining JoGL Exception while painting.
[scilab.git] / scilab / modules / gui / src / java / org / scilab / modules / gui / bridge / canvas / SwingScilabCanvasImpl.java
index 75161b1..a014c9b 100644 (file)
@@ -15,6 +15,7 @@ package org.scilab.modules.gui.bridge.canvas;
 
 import java.awt.Component;
 import java.awt.Frame;
+import java.awt.Graphics;
 import java.awt.HeadlessException;
 import java.util.Calendar;
 import java.util.StringTokenizer;
@@ -25,7 +26,6 @@ import javax.media.opengl.GLException;
 import javax.media.opengl.GLProfile;
 import javax.media.opengl.awt.GLCanvas;
 import javax.media.opengl.awt.GLJPanel;
-import javax.swing.SwingUtilities;
 
 import org.scilab.modules.action_binding.InterpreterManagement;
 import org.scilab.modules.commons.OS;
@@ -198,26 +198,34 @@ public class SwingScilabCanvasImpl {
     }
 
     /*
-     * Using GLJPanel for MacOSX may lead to a deadlock on deletion.
-     * Wrap call to removeNotify to ensure we are not outside Swing Thread
-     * and PBuffer is not locked.
+     * Using SafeGLJPanel for all platform to catch some EDT deletion/creation.
+     * Some buffer can be lost causing JoGL to crash
+     * http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6503420
      */
-    private final class MacOSXGLJPanel extends GLJPanel {
+    private final class SafeGLJPanel extends GLJPanel {
         private static final long serialVersionUID = -6166986369022555750L;
 
-        private void superRemoveNotify() {
-            super.removeNotify();
-        }
-
-        @Override
-        public void removeNotify() {
-            final MacOSXGLJPanel panel = this;
-            SwingUtilities.invokeLater(new Runnable() {
-                public void run() {
-                    panel.superRemoveNotify();
-                }
-            });
+        public void display() {
+            try {
+                super.display();
+            } catch (Exception e) {
+                // Catch JoGL Exceptions and hide it ...
+                // Make another try
+                //System.err.println("[SafeGLJPanel.display] catching "+e.toString());
+                super.reshape(getX(),getY(),getWidth(),getHeight());
+                super.display();
+            }
         }
+        
+       // protected void paintComponent(final Graphics g) {
+       //     try {
+       //         super.paintComponent(g);
+       //     } catch (Exception e) {
+       //         // Catch JoGL Exceptions and hide it ...
+       //         // Make another try
+       //         System.err.println("[SafeGLJPanel.paintComponent] catching "+e.toString());
+       //     }
+       // }
     }
 
     private static SwingScilabCanvasImpl me = null;
@@ -234,17 +242,7 @@ public class SwingScilabCanvasImpl {
         if (enableGLCanvas) {
             return new GLCanvas();
         } else {
-            /*
-             * Even with the good Java 1.6 version
-             * MacOSX does not manage mixing ligthweight and heavyweight components
-             * Use MacOSXGLJPanel as OpenGL component for now since GLJPanel will
-             * lead to deadlock on deletion.
-             */
-            //if (OS.get() == OS.MAC) {
-            //    return new MacOSXGLJPanel();
-            //} else {
-                return new GLJPanel();
-            //}
+            return new SafeGLJPanel();
         }
     }