diff --git a/swt/src/main/java/org/piccolo2d/extras/swt/SWTGraphics2D.java b/swt/src/main/java/org/piccolo2d/extras/swt/SWTGraphics2D.java index fa759a8..336fd11 100644 --- a/swt/src/main/java/org/piccolo2d/extras/swt/SWTGraphics2D.java +++ b/swt/src/main/java/org/piccolo2d/extras/swt/SWTGraphics2D.java @@ -1518,15 +1518,17 @@ final org.eclipse.swt.graphics.Font font = (org.eclipse.swt.graphics.Font) i.next(); font.dispose(); } + FONT_CACHE.clear(); for (final Iterator i = COLOR_CACHE.values().iterator(); i.hasNext();) { final org.eclipse.swt.graphics.Color color = (org.eclipse.swt.graphics.Color) i.next(); color.dispose(); } + COLOR_CACHE.clear(); for (final Iterator i = SHAPE_CACHE.values().iterator(); i.hasNext();) { final Path path = (Path) i.next(); path.dispose(); } + SHAPE_CACHE.clear(); } } - } diff --git a/swt/src/test/java/org/piccolo2d/extras/swt/SWTGraphics2DTest.java b/swt/src/test/java/org/piccolo2d/extras/swt/SWTGraphics2DTest.java new file mode 100644 index 0000000..f8b0896 --- /dev/null +++ b/swt/src/test/java/org/piccolo2d/extras/swt/SWTGraphics2DTest.java @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2008-2011, Piccolo2D project, http://piccolo2d.org + * Copyright (c) 1998-2008, University of Maryland + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided + * that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this list of conditions + * and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, this list of conditions + * and the following disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * None of the name of the University of Maryland, the name of the Piccolo2D project, or the names of its + * contributors may be used to endorse or promote products derived from this software without specific + * prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package org.piccolo2d.extras.swt; + +import org.eclipse.swt.layout.FillLayout; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Shell; + +import junit.framework.TestCase; + +/** + * Unit test for SWTGraphics2D. + */ +public class SWTGraphics2DTest extends TestCase { + + private Shell shell; + + /** {@inheritDoc} */ + public void setUp() { + shell = new Shell(Display.getDefault()); + shell.setLayout(new FillLayout()); + } + + public void testCacheCleanup() { + PSWTCanvas canvas = new PSWTCanvas(shell, 0); + PSWTText text = new PSWTText("test"); + canvas.getLayer().addChild(text); + canvas.dispose(); + canvas = new PSWTCanvas(shell, 0); + + //If caches return disposed object this will fail + text = new PSWTText("test"); + } +}