Index: applications/editors/josm/plugins/editgpx/src/org/openstreetmap/josm/plugins/editgpx/EditGpxMode.java
===================================================================
--- applications/editors/josm/plugins/editgpx/src/org/openstreetmap/josm/plugins/editgpx/EditGpxMode.java	(revision 28611)
+++ applications/editors/josm/plugins/editgpx/src/org/openstreetmap/josm/plugins/editgpx/EditGpxMode.java	(revision 28612)
@@ -128,19 +128,21 @@
      */
     private void paintRect(Point p1, Point p2) {
-        Graphics g = frame.getGraphics();//Main.map.mapView.getGraphics();
+        if (frame != null) {
+            Graphics g = frame.getGraphics();
 
-        Rectangle r = oldRect;
-        if (r != null) {
-            //overwrite old rct
+            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;
     }
 
@@ -178,3 +180,8 @@
     }
 
+    @Override
+    public void destroy() {
+        super.destroy();
+        MapView.removeLayerChangeListener(this);
+    }
 }
Index: applications/editors/josm/plugins/editgpx/src/org/openstreetmap/josm/plugins/editgpx/EditGpxPlugin.java
===================================================================
--- applications/editors/josm/plugins/editgpx/src/org/openstreetmap/josm/plugins/editgpx/EditGpxPlugin.java	(revision 28611)
+++ applications/editors/josm/plugins/editgpx/src/org/openstreetmap/josm/plugins/editgpx/EditGpxPlugin.java	(revision 28612)
@@ -47,8 +47,7 @@
     @Override
     public void mapFrameInitialized(MapFrame oldFrame, MapFrame newFrame) {
-        if(oldFrame == null && newFrame != null) {
-            mode.setFrame(newFrame);
-
-            if(Main.map != null)
+        mode.setFrame(newFrame);
+        if (oldFrame == null && newFrame != null) {
+            if (Main.map != null)
                 Main.map.addMapMode(btn);
         }
