mapbox / mapbox-gl-native

Interactive, thoroughly customizable maps in native Android, iOS, macOS, Node.js, and Qt applications, powered by vector tiles and OpenGL
https://mapbox.com/mobile
Other
4.37k stars 1.33k forks source link

[Android] Error due to latitude must not be NaN on getCameraForLatLngBounds #14037

Closed schachi5000 closed 4 years ago

schachi5000 commented 5 years ago

In our app we arbitrarily receive the following error, when trying to move the camera to a location defined by a bounding box.

java.lang.Error: latitude must not be NaN
    at com.mapbox.mapboxsdk.maps.NativeMapView.nativeGetCameraForLatLngBounds(NativeMethod)
    at com.mapbox.mapboxsdk.maps.NativeMapView.getCameraForLatLngBounds(NativeMapView.java:269)
    at com.mapbox.mapboxsdk.maps.MapboxMap.getCameraForLatLngBounds(MapboxMap.java:1446)

Expected behavior

CameraPosition should be provided so the camera can be animated to the new location.

Actual behavior

Crash due to java.lang.Error

Configuration

A LatLngBounds.Builder is used to create the LatLngBounds object.

LatLngBounds.Builder builder = new LatLngBounds.Builder();
builder.include(new LatLng(52f, 9f));
builder.include(new LatLng(52.1f, 9.1f));
LatLngBounds latLngBounds= builder.build();

If the provided latitude oder longitude were null, the constructor/setter in LatLng should have thrown the error. Instead it is thrown later in NativeMapView.nativeGetCameraForLatLngBounds()

Android versions: no specific version
Device models: no specific device Mapbox SDK versions: 7.1.2

tobrun commented 5 years ago

@schachi5000 thank you for reaching out and reporting your issue. I'm not able to reproduce your issue as:

Could you add a bit more context, or an example where the exception is only thrown in nativeGetCameraForLatLngBounds?

schachi5000 commented 5 years ago

Right. I've observed the same behavior you mentioned, while testing our code. So reproducing the issue locally was not possible. The stacktrace I've posted is something we get from our crash report system and sadly the only trace of the issue. We are using getCameraForLatLngBounds at only one location in our code and always with a LatLngBounds.Builder.

Correct me if I'm wrong here, but the only way to call getCameraForLatLngBounds() is with LatLngBounds. LatLngBounds can only be constructed with valid data, since it would throw IllegalArguementException if any data would be wrong.

If all of the above is correct there might be error in nativeGetCameraForLatLngBounds, since it should not be possible to pass a NaN.

tobrun commented 5 years ago

Thank you for following up, I'm as confused as your are atm :)

schachi5000 commented 5 years ago

One thing worth mentioning: The error only started to appear after we've updated the SDK from v6.3.0 to v7.1.2

julianrex commented 5 years ago

@tobrun - we have https://github.com/mapbox/mapbox-gl-native/issues/13938 on the iOS side, which may possibly be related - as it appears to be random. My first thought that it was invalid (non web-mercator) coordinates - and I continue to investigate that path - but those are likely to hit a CALayer exception.

schachi5000 commented 5 years ago

Hi there. Just a short FYI. We've updated the SDK now to 7.3.2 but the error still persists.

schachi5000 commented 5 years ago

Due to sheer luck I've stumbled about a way to recreate the error. The cause were the passed padding values. By using a few devices in landscape mode, the passed padding creates a rectangle too tight to process properly.

So it wasn't the passed LatLngBounds after all. Rather the calculated values by the method itself.

stale[bot] commented 4 years ago

This issue has been automatically detected as stale because it has not had recent activity and will be archived. Thank you for your contributions.

mabgroup commented 1 year ago

Due to sheer luck I've stumbled about a way to recreate the error. The cause were the passed padding values. By using a few devices in landscape mode, the passed padding creates a rectangle too tight to process properly.

So it wasn't the passed LatLngBounds after all. Rather the calculated values by the method itself.

Hi @schachi5000 I faced the same issue and I can't reproduce the exception. What did you do to stop this error? Can you give me the coordinates that produce the error?