Rescue: Crash touching outside world borders

134 views
Skip to first unread message

emux

unread,
Feb 15, 2014, 6:11:16 AM2/15/14
to mapsfo...@googlegroups.com
Hi Ludwig,

I'd like to report a crash that I saw at one of my apps,
but it's easy reproducible also at Samples app.

To see this, one can change at BasicMapViewer the setZoomLevelMin to 0
at line 134:
mapView.getMapZoomControls().setZoomLevelMin((byte) 0)
and line 250:
mvp.setZoomLevelMin((byte) 0)

Then run "Downloading Mapnik" example, zoom out completely
and touch the map at gray area outside the world borders,
where there are not any map tiles.

The application crashes with the following:

FATAL EXCEPTION: main
Process: org.mapsforge.applications.android.samples, PID: 2108
java
.lang.IllegalArgumentException: invalid pixelY coordinate at zoom level 0: -93.80928004837207
    at org
.mapsforge.core.util.MercatorProjection.pixelYToLatitude(MercatorProjection.java:385)
    at org
.mapsforge.map.util.MapViewProjection.fromPixels(MapViewProjection.java:56)
    at org
.mapsforge.map.android.input.TouchEventHandler.onActionDown(TouchEventHandler.java:123)
    at org
.mapsforge.map.android.input.TouchEventHandler.onTouchEvent(TouchEventHandler.java:85)
    at org
.mapsforge.map.android.view.MapView.onTouchEvent(MapView.java:143)

Best regards, Emux
Cruiser - Cruiser Beta - Atlas

Ludwig

unread,
Feb 15, 2014, 8:41:18 AM2/15/14
to mapsfo...@googlegroups.com
I have not tried, but I can see this happening. Obviously when totally zoomed out, it will be possible that there are pixels that do not correspond to map coordinates.

Question really is what to do with it:
  • For longitudes the computation could wrap around, but then, at least at the moment, there is no other support for wrapping around such as tiling around the world (and it would not be high on my list, it is actually tricky to get right and there is a good reason they put the dateline somewhere into the Pacific ocean.) 
  • For latitudes this is, IIRC, not possible in spherical mercator. It just stops working once you get close to the poles.
Obviously there should be no crash. Should invalid coordinates just be eaten by the touch handler? (I am not sure if this is user friendly). Throw a specific exception in MercatorProjection that can be caught by the user code?

If someone has a good (=easy and consistent) model for the expected behaviour, let me know.

Ludwig





--
You received this message because you are subscribed to the Google Groups "mapsforge-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mapsforge-de...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mapsforge-dev/990cbf30-46c7-4977-8d0a-13f7c0cccb30%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

emux

unread,
Feb 15, 2014, 9:28:03 AM2/15/14
to mapsfo...@googlegroups.com
No, I'm not talking about change at mapsforge map behavior i.e. map tiles wrap around.

I mean, as you said, a more user friendly way, so that developer
can decide for the exception and prevent mapsforge internal crash.

The same issue can happen also at Java MouseListener
e.g. at Atlas double click implementation, I catch the exception

I'll check more the code and propose some idea / patch.


Best regards, Emux
Cruiser - Cruiser Beta - Atlas

Ludwig

unread,
Feb 15, 2014, 9:43:13 AM2/15/14
to mapsfo...@googlegroups.com

Maybe an illegal coordinates exception.

emux

unread,
Feb 15, 2014, 11:14:52 AM2/15/14
to mapsfo...@googlegroups.com
Should invalid coordinates just be eaten by the touch handler? (I am not sure if this is user friendly).

TouchEventHandler only at onActionDown needs to compute the geographic coordinates of touch point.
There, if geographic coordinates are invalid, catching the exc and return true, allows the touch to be performed.
What do you think?

I attach the patch.
TouchEventHandler.patch

Ludwig

unread,
Feb 15, 2014, 10:39:47 PM2/15/14
to mapsfo...@googlegroups.com
I guess it is the most simple solution, so +1. Done.

Ludwig


--
You received this message because you are subscribed to the Google Groups "mapsforge-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mapsforge-de...@googlegroups.com.

emux

unread,
Feb 16, 2014, 8:05:18 AM2/16/14
to mapsfo...@googlegroups.com
I think one more check is needed at onActionUp method,
if lastLatLong is null.


I attach the patch.

Best regards, Emux
Cruiser - Cruiser Beta - Atlas

TouchEventHandler2.patch

Ludwig

unread,
Feb 16, 2014, 8:30:19 AM2/16/14
to mapsfo...@googlegroups.com

Aurelian Cotuna

unread,
Mar 6, 2014, 2:07:32 PM3/6/14
to mapsfo...@googlegroups.com
Hey guys,
Are these patches added to library jars?

Or can somebody tell me how to apply these patches?:)

Thanks,
Ark

emux

unread,
Mar 6, 2014, 2:12:56 PM3/6/14
to mapsfo...@googlegroups.com
Yes they have been committed to the repository
and they also exist in builded jars at Jenkins.


Best regards, Emux
Cruiser - Cruiser Beta

Aurelian Cotuna

unread,
Mar 6, 2014, 2:25:55 PM3/6/14
to mapsfo...@googlegroups.com
Hey guys,
I have tested this and it seems to work, but there is a bug similar to this one.

Steps to reproduce:
1. Zoom the map out to maximum.
2. Zoom in below 1 meter.

The map crashes with this exception:

java.lang.IllegalArgumentException: left: 2.147483647E9, right: -2.147483529E9
            at org.mapsforge.core.model.Rectangle.<init>(Rectangle.java:32)
            at org.mapsforge.map.layer.overlay.Marker.draw(Marker.java:80)
            at org.mapsforge.map.android.layer.MyLocationOverlay.draw(MyLocationOverlay.java:142)
            at org.mapsforge.map.layer.LayerManager.doWork(LayerManager.java:94)
            at org.mapsforge.map.util.PausableThread.run(PausableThread.java:140)


I can reproduce this on a nexus 5, Android 4.4 and Nexus 4 android 4.3

I hope this is useful :)

emux

unread,
Mar 6, 2014, 3:21:32 PM3/6/14
to mapsfo...@googlegroups.com
Well I use my own complex my location implementation,
so I have not seen so far such an exception.

But to understand better your steps.
You use raster map (e.g. Mapnik) with my location overlay,
zoom out to level 0 and then zoom in to max zoom (i.e. level 18) ?


Best regards, Emux
Cruiser - Cruiser Beta

Aurelian Cotuna

unread,
Mar 6, 2014, 3:40:38 PM3/6/14
to mapsfo...@googlegroups.com
Hey emux,
I use an offline map file for map with mylocation overlay. Over MyLocationOverlay I also put some Markers.
I zoom out to level 0, and all the markers are rendered correctly. I zoom in to max zoom level (using pinch to zoom, or double tap) and when I'm under 1 m, tiles are not rendered at all, and the map crashes with that exception.

Best regards,
Ark
Reply all
Reply to author
Forward
0 new messages