altoslib: Don't crash when map flight data is missing
authorKeith Packard <keithp@keithp.com>
Wed, 25 Sep 2019 20:09:22 +0000 (13:09 -0700)
committerKeith Packard <keithp@keithp.com>
Wed, 25 Sep 2019 20:09:22 +0000 (13:09 -0700)
Just a couple of null pointer checks to allow the map display to come
up even when no data are available.

Signed-off-by: Keith Packard <keithp@keithp.com>
altoslib/AltosMap.java
altosuilib/AltosUIGraph.java
altosuilib/AltosUIMap.java

index 69142c3..8fc40e8 100644 (file)
@@ -499,6 +499,8 @@ public class AltosMap implements AltosMapTileListener, AltosMapStoreListener {
                notice_user_input();
                if (path == null)
                        return null;
+               if (transform == null)
+                       return null;
                AltosLatLon     at = transform.screen_lat_lon(new  AltosPointInt(x, y));
                return path.nearest(at);
        }
index 098e9a5..da02451 100644 (file)
@@ -137,7 +137,8 @@ public class AltosUIGraph implements AltosUnitsListener, AltosShapeListener {
                this.series = null;
                this.axis_index = 0;
 
-               enable.register_shape_listener(this);
+               if (enable != null)
+                       enable.register_shape_listener(this);
 
                axes_added = new Hashtable<Integer,Boolean>();
 
index 5b981d1..bd0a855 100644 (file)
@@ -148,16 +148,16 @@ public class AltosUIMap extends JComponent implements AltosFlightDisplay, AltosM
                public void mouseMoved(MouseEvent e) {
                        AltosMapPathPoint point = map.nearest(e.getPoint().x, e.getPoint().y);
 
-                       if (nearest_mark == null)
-                               nearest_mark = map.add_mark(point.gps.lat,
-                                                           point.gps.lon,
-                                                           point.state);
-                       else {
-                               nearest_mark.lat_lon.lat = point.gps.lat;
-                               nearest_mark.lat_lon.lon = point.gps.lon;
-                               nearest_mark.state = point.state;
-                       }
                        if (point != null) {
+                               if (nearest_mark == null)
+                                       nearest_mark = map.add_mark(point.gps.lat,
+                                                                   point.gps.lon,
+                                                                   point.state);
+                               else {
+                                       nearest_mark.lat_lon.lat = point.gps.lat;
+                                       nearest_mark.lat_lon.lon = point.gps.lon;
+                                       nearest_mark.state = point.state;
+                               }
                                nearest_label.setText(String.format("%9.2f sec %s%s%s%s",
                                                                    point.time,
                                                                    pos(point.gps.lat,