You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
What steps will reproduce the problem?
1. add a PSwing node to another PNode
2. remove the PSwing node's parent from the canvas
3. force a garbage collection
What is the expected output? What do you see instead?
The PSwing node and its parent PNode should be collected because they are
no longer part of the canvas. Instead, they are held in memory by the
Swing object that is contained in the PSwing node.
Here is the proposed fix to the PSwing class:
Index: C:/dev/piccolo.java-all/extras/edu/umd/cs/piccolox/pswing/PSwing.java
===================================================================
--- C:/dev/piccolo.java-all/extras/edu/umd/cs/piccolox/pswing/PSwing.java
(revision 3)
+++ C:/dev/piccolo.java-all/extras/edu/umd/cs/piccolox/pswing/PSwing.java
(revision 4)
@@ -187,10 +187,12 @@
/*The parent listener for camera/canvas changes*/
private PropertyChangeListener parentListener = new
PropertyChangeListener() {
public void propertyChange( PropertyChangeEvent evt ) {
- PNode source = (PNode)evt.getSource();
- PNode parent = source.getParent();
+ PNode parent = (PNode) evt.getNewValue();
+ clearListeners((PNode) evt.getOldValue());
if( parent != null ) {
listenForCanvas( parent );
+ } else {
+ updateCanvas( null );
}
}
@@ -478,7 +480,12 @@
PNode parent = p;
// System.out.println( "parent = " + parent.getClass() );
- if( parent instanceof PLayer ) {
+ if (parent instanceof PCamera) {
+ PCamera cam = (PCamera) parent;
+ if( cam.getComponent() instanceof PSwingCanvas ) {
+ updateCanvas( (PSwingCanvas)cam.getComponent() );
+ }
+ } else if( parent instanceof PLayer ) {
PLayer player = (PLayer)parent;
// System.out.println( "Found player: with " +
player.getCameraCount() + " cameras" );
for( int i = 0; i < player.getCameraCount(); i++ ) {
@@ -521,6 +528,22 @@
}
/**
+ * Clear out all the listeners registered to make sure there are no
stray references
+ *
+ * @param fromParent Parent to start with for clearing listeners
+ */
+ private void clearListeners(PNode fromParent) {
+ if (fromParent == null) {
+ return;
+ }
+ if (listeningTo(fromParent)) {
+ fromParent.removePropertyChangeListener(
PNode.PROPERTY_PARENT, parentListener );
+ listeningTo.remove(fromParent);
+ clearListeners(fromParent.getParent());
+ }
+ }
+
+ /**
* Removes this PSwing from previous PSwingCanvas (if any), and ensure
that this PSwing is attached to the new PSwingCanvas.
* @param newCanvas the new PSwingCanvas (may be null)
*/
@@ -529,8 +552,8 @@
if( canvas != null ) {
canvas.removePSwing( this );
}
+ canvas = newCanvas;
if( newCanvas != null ) {
- canvas = newCanvas;
canvas.addPSwing( this );
reshape();
repaint();
Original issue reported on code.google.com by steveonjava on 23 Jun 2008 at 11:18
The text was updated successfully, but these errors were encountered:
Original issue reported on code.google.com by
steveonjava
on 23 Jun 2008 at 11:18The text was updated successfully, but these errors were encountered: