From: Calixte DENIZET Date: Fri, 20 Sep 2013 14:37:26 +0000 (+0200) Subject: Scirenderer: Fix memleak: textures were not correctly disposed X-Git-Tag: 5.5.0-beta-1~122 X-Git-Url: http://gitweb.scilab.org/?p=scilab.git;a=commitdiff_plain;h=8c1e9d1cfc19de1c24bfaebeebc746c8ee615d4e Scirenderer: Fix memleak: textures were not correctly disposed Change-Id: I080adac89188d3db3df4694f5840774d75a5a4e5 --- diff --git a/scilab/modules/scirenderer/src/org/scilab/forge/scirenderer/implementation/jogl/texture/JoGLTextureManager.java b/scilab/modules/scirenderer/src/org/scilab/forge/scirenderer/implementation/jogl/texture/JoGLTextureManager.java index 83ba612..1312bbb 100644 --- a/scilab/modules/scirenderer/src/org/scilab/forge/scirenderer/implementation/jogl/texture/JoGLTextureManager.java +++ b/scilab/modules/scirenderer/src/org/scilab/forge/scirenderer/implementation/jogl/texture/JoGLTextureManager.java @@ -52,7 +52,6 @@ import java.util.Set; public class JoGLTextureManager implements TextureManager { private final Set allTextures = new HashSet(); - private final Set toDispose = new HashSet(); JoGLCanvas canvas; public JoGLTextureManager(JoGLCanvas canvas) { @@ -142,9 +141,7 @@ public class JoGLTextureManager implements TextureManager { public void dispose(Texture texture) { if ((texture instanceof JoGLTexture) && (allTextures.contains((JoGLTexture) texture))) { allTextures.remove((JoGLTexture) texture); - synchronized (toDispose) { - toDispose.add((JoGLTexture) texture); - } + ((JoGLTexture) texture).dispose(); } } @@ -160,6 +157,7 @@ public class JoGLTextureManager implements TextureManager { private double tfactor = 1; private ByteBuffer buffer; private TextureDataProvider.ImageType previousType; + private JoGLDrawingTools drawingTools; /** * Default constructor. @@ -177,6 +175,10 @@ public class JoGLTextureManager implements TextureManager { * @throws SciRendererException if the texture is invalid. */ public synchronized void bind(JoGLDrawingTools drawingTools) throws SciRendererException { + if (this.drawingTools == null) { + this.drawingTools = this.drawingTools; + } + GL2 gl = drawingTools.getGl().getGL2(); if (isValid()) { checkData(drawingTools); @@ -216,16 +218,6 @@ public class JoGLTextureManager implements TextureManager { * @throws SciRendererException if the texture is too big. */ private synchronized void checkData(JoGLDrawingTools drawingTools) throws SciRendererException { - synchronized (toDispose) { - if (!toDispose.isEmpty()) { - final GL2 gl = drawingTools.getGl().getGL2(); - for (JoGLTexture jt : toDispose) { - jt.releaseTextures(gl); - } - toDispose.clear(); - } - } - if (isValid() && !upToDate) { GL2 gl = drawingTools.getGl().getGL2(); @@ -319,6 +311,12 @@ public class JoGLTextureManager implements TextureManager { } } + public void dispose() { + if (drawingTools != null) { + releaseTextures(drawingTools.getGl().getGL2()); + } + } + public boolean preDraw(JoGLDrawingTools drawingTools) throws SciRendererException { checkData(drawingTools);