That's definitely a stupid bug -- MovablePortrayal2D is calling getObjectPosition and if there's no object for some reason (which is surprising actually) getObjectPosition returns null, which MovablePortrayal2D doesn't account for.
Here's some revised code for MovablePortrayal2D. Let me know if things work now.
On Aug 8, 2012, at 3:11 PM, Chris Wray wrote:
> I am new to MASON (and this list) and working through the tutorial (student schoolyard cliques) and "tinkering" with the code in a bid to learn how to use MASON, etc, etc.
> The code I have is upto p.41 in the mason manual (so new MovablePortrayal2D, new CircledPortrayal2D, new LabelledPortrayal2D have just been added).
> So the code I am working with resembles the code in this tutorial very much, except that I have made the "students" fixed nodes in the ContinuousPortrayal2D.
> I have also made it possible for the students/nodes to be removed (whilst the simulation is paused, etc) whilst selecting/inspecting the individual nodes via the GUI.
> I do the "removing" of nodes by iterating over students.buddies and removing the desired object via .removeNode, and I then .remove the same object from students.yard.
> So far, so good: I run the simulation, pause, select a node, remove it (via boolean inspector property), the display updates, and the edges and node vanish.
> My problem: As soon as I select another "node" in the display, I get a "NullPointerException" with messages:
> at sim.portrayal.simple.MovablePortrayal2D.handleMouseEvent(MovablePortrayal2D.java:81)
> at sim.display.Display2D.handleMouseEvent(Display2D.java:1846)
> at sim.display.Display2D$6.mousePressed(Display2D.java:1208)
> at java.awt.AWTEventMulticaster.mousePressed(Unknown Source)
> at java.awt.Component.processMouseEvent(Unknown Source)
> at javax.swing.JComponent.processMouseEvent(Unknown Source)
> at java.awt.Component.processEvent(Unknown Source)
> at java.awt.Container.processEvent(Unknown Source)
> at java.awt.Component.dispatchEventImpl(Unknown Source)
> at java.awt.Container.dispatchEventImpl(Unknown Source)
> at java.awt.Component.dispatchEvent(Unknown Source)
> at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
> at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
> I suspect this is because I "removed" an object, whilst it was being "pointed to" (selected in the GUI).
> My question: is there a "good" way to remove objects from the display, and how could I handle an event such as the above?
> Many thanks, C.