react-native-mapbox-gl icon indicating copy to clipboard operation
react-native-mapbox-gl copied to clipboard

InvalidLatLngBoundsException - Cannot create a LatLngBounds from 1 items

Open benjaminkoetting opened this issue 7 years ago • 10 comments
trafficstars

we got this exception sometimes on a production build:

com.mapbox.mapboxsdk.exceptions.InvalidLatLngBoundsException: Cannot create a LatLngBounds from 1 items
    at com.mapbox.mapboxsdk.geometry.LatLngBounds$Builder.build(LatLngBounds.java:440)
    at com.mapbox.mapboxsdk.maps.Projection.getVisibleRegion(Projection.java:112)
    at com.mapbox.rctmgl.components.mapview.RCTMGLMapView.makeRegionPayload(RCTMGLMapView.java:1173)
    at com.mapbox.rctmgl.components.mapview.RCTMGLMapView.sendRegionChangeEvent(RCTMGLMapView.java:1369)
    at com.mapbox.rctmgl.components.mapview.RCTMGLMapView.access$700(RCTMGLMapView.java:90)
    at com.mapbox.rctmgl.components.mapview.RCTMGLMapView$3.onCameraIdle(RCTMGLMapView.java:416)
    at com.mapbox.mapboxsdk.maps.CameraChangeDispatcher$4.run(CameraChangeDispatcher.java:106)
    at android.os.Handler.handleCallback(Handler.java:751)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:154)
    at android.app.ActivityThread.main(ActivityThread.java:6119)
    at java.lang.reflect.Method.invoke(Method.java)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)

at the moment it is 100% Android, how we can catch this exception?

Thanks, Ben

benjaminkoetting avatar Apr 06 '18 11:04 benjaminkoetting

@bemazo yes this looks like we're trying to send an event up to the Javascript and when we create the bounds we're only passing in one lat/lng, we should add better logic to prevent this from ever attempting to create a bound.

Do you know what steps you need to take to hit this scenario it's happening, all in the native Android SDK, so I'm wondering if we're calling a method before the projection object is actually ready.

Thanks for reporting!

nitaliano avatar Apr 06 '18 17:04 nitaliano

@nitaliano sorry at the moment I cannot reproduce it, I see it only sometimes in our sentry system with the stacktrace. So it must something during the runtime. Can it happend when we call setCamera with wrong parameters?

benjaminkoetting avatar Apr 09 '18 06:04 benjaminkoetting

We're seeing a lot of these (Android only) now after upgrading to RN 0.59. We currently have a dependency to this commit: https://github.com/nitaliano/react-native-mapbox-gl/commit/7ed29351081d5e34e895c95cb28b823f19d6b327. I know this is an old issue, but is there any pointer now to how we can solve this @nitaliano?

kimhafr avatar Mar 25 '19 20:03 kimhafr

@KimAM I'm using this hack https://github.com/janicduplessis/react-native-mapbox-gl/commit/4edfefe0f52e26db49fefa652cc2a73bb2ffa0c4#diff-83bd90811e16ee14c9357ca5dd70f50cR1294, doesn't seem to cause issues but is definitely not a proper fix.

janicduplessis avatar Mar 30 '19 17:03 janicduplessis

Thanks @janicduplessis 🙌

kimhafr avatar Mar 31 '19 06:03 kimhafr

As per discussion in #586, the root cause is likely an onRegionDidChange event that should/may be triggered as the Mapbox view is dismounted.

To all who have reported this issue, can you confirm that you are dismounting a Mapbox.MapView, for instance by having the view inside a nested navigator or another conditional render?

My hypothesis is that as RN is dismounting the view, onCameraIdle may be triggered by the native SDK. This will in turn create a race condition where the view dimensions can be [0, 0], making getVisibleRegion only return a single coordinate instead of a pair.

Imo, the proper fix should be to check map dimensions and only return the callback if both dimensions are > 0.

kristfal avatar Apr 01 '19 19:04 kristfal

@kristfal This was also our conclusion in a past we did last year to solve this error: https://github.com/innovactorybv/react-native-mapbox-gl/commit/b19842b9d5dafc651841746182ec6fe4a25d7908#diff-83bd90811e16ee14c9357ca5dd70f50cR1015

...
} catch (exception: InvalidLatLngBoundsException) {
    // ignore invalid latlng exceptions, was seen happening during component unmounts
}

I agree with a better check 👍 I just wanted to confirm that, at the time, we've seen the same correlation with the component being unmounted.

mattijsf avatar Apr 01 '19 20:04 mattijsf

Can confirm that this crash occurs when the component is being unmounted 👍

kimhafr avatar Apr 02 '19 08:04 kimhafr

Ah well, it's a little bit diffent when unmounting. It does not have: Cannot create a LatLngBounds from 1 items

com.mapbox.mapboxsdk.exceptions.InvalidLatLngBoundsException: 
  at com.mapbox.mapboxsdk.geometry.LatLngBounds$Builder.build (LatLngBounds.java:440)
  at com.mapbox.mapboxsdk.maps.Projection.getVisibleRegion (Projection.java:112)
  at com.mapbox.rctmgl.components.mapview.RCTMGLMapView.makeRegionPayload (RCTMGLMapView.java:1263)
  at com.mapbox.rctmgl.components.mapview.RCTMGLMapView.handleMapChangedEvent (RCTMGLMapView.java:1473)
  at com.mapbox.rctmgl.components.mapview.RCTMGLMapView.access$1000 (RCTMGLMapView.java:91)
  at com.mapbox.rctmgl.components.mapview.RCTMGLMapView$7.onCameraMove (RCTMGLMapView.java:485)
  at com.mapbox.mapboxsdk.maps.CameraChangeDispatcher$2.run (CameraChangeDispatcher.java:67)
  at android.os.Handler.handleCallback (Handler.java:789)
  at android.os.Handler.dispatchMessage (Handler.java:98)
  at android.os.Looper.loop (Looper.java:164)
  at android.app.ActivityThread.main (ActivityThread.java:6944)
  at java.lang.reflect.Method.invoke (Native Method)
  at com.android.internal.os.Zygote$MethodAndArgsCaller.run (Zygote.java:327)
  at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1374)

RichardLindhout avatar Apr 13 '19 14:04 RichardLindhout

No fix on this issue?

suvro24 avatar Jun 28 '19 04:06 suvro24