From 88ef7b1007174cb0e7346cf4f1240367274afc26 Mon Sep 17 00:00:00 2001 From: Bruno JOFRET Date: Tue, 15 Jan 2013 15:24:46 +0100 Subject: [PATCH] Catch remaining JoGL Exception while painting. Change-Id: I66f552701080e39c8cd5f96210b86e7cea9d0b14 --- .../src/java/org/scilab/modules/gui/SwingView.java | 25 ++++++++- .../gui/bridge/canvas/SwingScilabCanvasImpl.java | 54 ++++++++++---------- 2 files changed, 49 insertions(+), 30 deletions(-) diff --git a/scilab/modules/gui/src/java/org/scilab/modules/gui/SwingView.java b/scilab/modules/gui/src/java/org/scilab/modules/gui/SwingView.java index fb1178d..a7419f8 100644 --- a/scilab/modules/gui/src/java/org/scilab/modules/gui/SwingView.java +++ b/scilab/modules/gui/src/java/org/scilab/modules/gui/SwingView.java @@ -316,8 +316,29 @@ public final class SwingView implements GraphicView { } private TypedObject CreateObjectFromType(final int type, final String id) { - UielementType enumType = StyleToEnum(type); - return new TypedObject(enumType, CreateObjectFromType(enumType, id)); + final UielementType enumType = StyleToEnum(type); + final SwingViewObject newSVObject[] = new SwingViewObject[1]; + if (SwingUtilities.isEventDispatchThread()) { + newSVObject[0] = CreateObjectFromType(enumType, id); + } else { + try { + SwingUtilities.invokeAndWait(new Runnable() { + + @Override + public void run() { + newSVObject[0] = CreateObjectFromType(enumType, id); + + } + }); + } catch (InterruptedException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (InvocationTargetException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + return new TypedObject(enumType, newSVObject[0]); } private SwingViewObject CreateObjectFromType(UielementType type, String id) { diff --git a/scilab/modules/gui/src/java/org/scilab/modules/gui/bridge/canvas/SwingScilabCanvasImpl.java b/scilab/modules/gui/src/java/org/scilab/modules/gui/bridge/canvas/SwingScilabCanvasImpl.java index 75161b1..a014c9b 100644 --- a/scilab/modules/gui/src/java/org/scilab/modules/gui/bridge/canvas/SwingScilabCanvasImpl.java +++ b/scilab/modules/gui/src/java/org/scilab/modules/gui/bridge/canvas/SwingScilabCanvasImpl.java @@ -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(); } } -- 1.7.9.5