Index: applications/editors/josm/plugins/junctionchecking/src/org/openstreetmap/josm/plugins/JunctionChecker/JunctionCheckerMapMode.java
===================================================================
--- applications/editors/josm/plugins/junctionchecking/src/org/openstreetmap/josm/plugins/JunctionChecker/JunctionCheckerMapMode.java	(revision 27966)
+++ applications/editors/josm/plugins/junctionchecking/src/org/openstreetmap/josm/plugins/JunctionChecker/JunctionCheckerMapMode.java	(revision 28610)
@@ -138,19 +138,21 @@
 	 */
 	private void paintRect(Point p1, Point p2) {
-		Graphics g = frame.getGraphics();//Main.map.mapView.getGraphics();
-
-		Rectangle r = oldRect;
-		if (r != null) {
-			//overwrite old rct
+		if (frame != null) {
+			Graphics g = frame.getGraphics();
+	
+			Rectangle r = oldRect;
+			if (r != null) {
+				//overwrite old rct
+				g.setXORMode(Color.BLACK);
+				g.setColor(Color.WHITE);
+				g.drawRect(r.x,r.y,r.width,r.height);
+			}
+	
 			g.setXORMode(Color.BLACK);
 			g.setColor(Color.WHITE);
+			r = createRect(p1,p2);
 			g.drawRect(r.x,r.y,r.width,r.height);
+			oldRect = r;
 		}
-
-		g.setXORMode(Color.BLACK);
-		g.setColor(Color.WHITE);
-		r = createRect(p1,p2);
-		g.drawRect(r.x,r.y,r.width,r.height);
-		oldRect = r;
 	}
 
@@ -162,3 +164,9 @@
 		this.digraph = digraph;
 	}
+
+	@Override
+	public void destroy() {
+		super.destroy();
+		MapView.removeLayerChangeListener(this);
+	}
 }
Index: applications/editors/josm/plugins/junctionchecking/src/org/openstreetmap/josm/plugins/JunctionChecker/JunctionCheckerPlugin.java
===================================================================
--- applications/editors/josm/plugins/junctionchecking/src/org/openstreetmap/josm/plugins/JunctionChecker/JunctionCheckerPlugin.java	(revision 27966)
+++ applications/editors/josm/plugins/junctionchecking/src/org/openstreetmap/josm/plugins/JunctionChecker/JunctionCheckerPlugin.java	(revision 28610)
@@ -49,9 +49,9 @@
 	@Override
 	public void mapFrameInitialized(MapFrame oldFrame, MapFrame newFrame) {
+		jcMapMode.setFrame(newFrame);
 		if (newFrame != null) {
 			junctionCheckDialog = new JunctionCheckDialog(this);
 			newFrame.addToggleDialog(junctionCheckDialog);
 			MapView.addLayerChangeListener(this);
-			jcMapMode.setFrame(newFrame);
 		} else
 			MapView.removeLayerChangeListener(this);
