Revision: 1106
Author: atdixon
Date: Sat Feb 26 14:52:57 2011
Log: Issue 206; apply patch and unit test to clear swt resource caches
http://code.google.com/p/piccolo2d/source/detail?r=1106
Added:
/piccolo2d.java/branches/release-1.3/swt/src/test/java/edu/umd/cs/piccolox/swt/SWTGraphics2DTest.java
Modified:
/piccolo2d.java/branches/release-1.3/swt/pom.xml
/piccolo2d.java/branches/release-1.3/swt/src/main/java/edu/umd/cs/piccolox/swt/SWTGraphics2D.java
=======================================
--- /dev/null
+++
/piccolo2d.java/branches/release-1.3/swt/src/test/java/edu/umd/cs/piccolox/swt/SWTGraphics2DTest.java
Sat Feb 26 14:52:57 2011
@@ -0,0 +1,59 @@
+/*
+ * 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 edu.umd.cs.piccolox.swt;
+
+import junit.framework.TestCase;
+import org.eclipse.swt.layout.FillLayout;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Shell;
+
+/**
+ * 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");
+ }
+}
=======================================
--- /piccolo2d.java/branches/release-1.3/swt/pom.xml Thu Dec 23 10:36:30
2010
+++ /piccolo2d.java/branches/release-1.3/swt/pom.xml Sat Feb 26 14:52:57
2011
@@ -59,6 +59,16 @@
<developerConnection>scm:svn:https://piccolo2d.googlecode.com/svn/piccolo2d.java/branches/release-1.3/swt</developerConnection>
<url>http://code.google.com/p/piccolo2d/source/browse/piccolo2d.java/branches/release-1.3/swt</url>
</scm>
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <argLine>${surefire.argLine}</argLine>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
<reporting>
<plugins>
<plugin>
@@ -293,6 +303,7 @@
<properties>
<swt.groupId>org.eclipse.swt.cocoa</swt.groupId>
<swt.artifactId>macosx</swt.artifactId>
+ <surefire.argLine>-XstartOnFirstThread</surefire.argLine>
</properties>
</profile>
-->
=======================================
---
/piccolo2d.java/branches/release-1.3/swt/src/main/java/edu/umd/cs/piccolox/swt/SWTGraphics2D.java
Tue Dec 21 14:13:15 2010
+++
/piccolo2d.java/branches/release-1.3/swt/src/main/java/edu/umd/cs/piccolox/swt/SWTGraphics2D.java
Sat Feb 26 14:52:57 2011
@@ -1548,14 +1548,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();
}
}
--
Piccolo2D Developers Group: http://groups.google.com/group/piccolo2d-dev?hl=en