Cross DrawerVisitor dispose/finalize may kill wrong JoGL component. 77/10477/4
Bruno JOFRET [Thu, 14 Feb 2013 13:00:34 +0000 (14:00 +0100)]
Change-Id: I02c318649f952f23599c6733b42a3ac2c3108253

scilab/modules/gui/src/java/org/scilab/modules/gui/bridge/canvas/SwingScilabCanvasImpl.java
scilab/modules/renderer/src/java/org/scilab/modules/renderer/JoGLView/DrawerVisitor.java

index 451ae1c..a37d4bb 100644 (file)
@@ -15,7 +15,6 @@ 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;
index 9cd8130..db61a49 100644 (file)
@@ -16,7 +16,6 @@ import org.scilab.forge.scirenderer.Drawer;
 import org.scilab.forge.scirenderer.DrawingTools;
 import org.scilab.forge.scirenderer.SciRendererException;
 import org.scilab.forge.scirenderer.buffers.ElementsBuffer;
-import org.scilab.forge.scirenderer.implementation.jogl.JoGLCanvas;
 import org.scilab.forge.scirenderer.shapes.appearance.Appearance;
 import org.scilab.forge.scirenderer.shapes.geometry.DefaultGeometry;
 import org.scilab.forge.scirenderer.shapes.geometry.Geometry;
@@ -932,6 +931,10 @@ public class DrawerVisitor implements Visitor, Drawer, GraphicView {
 
     @Override
     public void deleteObject(String id) {
+        if (isImmediateDrawing(id)) {
+            canvas.redraw();
+        }
+        
         dataManager.dispose(id);
         markManager.dispose(id);
         textManager.dispose(id);
@@ -939,27 +942,26 @@ public class DrawerVisitor implements Visitor, Drawer, GraphicView {
         axesDrawer.dispose(id);
         legendDrawer.dispose(id);
         fecDrawer.dispose(id);
-        textureManager.dispose(id);
-
-        GraphicObject object = GraphicController.getController().getObjectFromId(id);
-        if (object instanceof Figure && visitorMap.containsKey(id)) {
-            visitorMap.remove(id);
-            GraphicController.getController().unregister(this);
-            if (SwingUtilities.isEventDispatchThread()) {
-                canvas.destroy();
-            } else {
-                try {
-                    SwingUtilities.invokeAndWait(new Runnable() {
-                            public void run() {
-                                canvas.destroy();
-                            }
-                        });
-                } catch (Exception e) { }
-            }
+        textureManager.dispose(id); 
+        /*
+         * Check we are deleting Figure managed by DrawerVisitor(this)
+         * Otherwise do nothing on deletion.
+         */
+        if (!figure.getIdentifier().equals(id)) {
+            return;
+        }
+        visitorMap.remove(id);
+        GraphicController.getController().unregister(this);
+        if (SwingUtilities.isEventDispatchThread()) {
+            canvas.destroy();
         } else {
-            if (isImmediateDrawing(id)) {
-                canvas.redraw();
-            }
+            try {
+                SwingUtilities.invokeAndWait(new Runnable() {
+                    public void run() {
+                        canvas.destroy();
+                    }
+                });
+            } catch (Exception e) { }
         }
     }