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 69142c375c3656bf37b1c75a3d80a260dd994b40..8fc40e8af307057a269e2552271ed09f0a47d060 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 098e9a52f17ebe28add7f8f3829f10f86279f278..da02451310416c47627a8a1b4251a5110d080f91 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 5b981d14e6113f2fa9d24c5a3616168295329c9d..bd0a855c01ee6468c549bbdafeb3af6ebb0bfe44 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,