mapbox / mapbox-navigation-android

Mapbox Navigation SDK for Android
https://docs.mapbox.com/android/navigation/overview/
Other
622 stars 319 forks source link

Passing a Route from v5.MapboxDirections into NavigationView Crashes #4038

Open NathanaelA opened 3 years ago

NathanaelA commented 3 years ago

Mapbox Navigation SDK version: com.mapbox.mapboxsdk:mapbox-android-sdk:9.6.0 (And current master as of Feb 18th, 2021)

Steps to trigger behavior

  1. Create a route using 'com.mapbox.api.directions.v5.MapboxDirections.builder()'
  2. Origin & Destination are: 29.0508283 -80.90549659999999 & 29.0485303934386 -80.90262127450215 (But I don't believe this matters, what matters is no waypoints)
  3. The retrofit callback from the enqueueCall returns what appears to be a valid route which I assign the first one to currentRoute.
    • I print out the legs() of the currentRoute, the output is this: [RouteLeg{distance=524.076, duration=71.744, durationTypical=null, summary=North Atlantic Avenue, Beachway Avenue, admins=[Admin{countryCode=US, countryCodeAlpha3=USA}], steps=[], incidents=null, annotation=null}]
    • The important thing to notice in this is steps
  4. Call: this._mapbox.drawRoute(currentRoute); (or call this._mapbox.startNavigation using this route)

Expected behavior

Works and doesn't crash

Actual behavior

Same callstack as #3449

java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
        at java.util.ArrayList.get(ArrayList.java:437)
        at com.mapbox.services.android.navigation.ui.v5.route.MapRouteLine.buildWayPointFeatureFromLeg(MapRouteLine.java:359)
        at com.mapbox.services.android.navigation.ui.v5.route.MapRouteLine.buildWayPointFeatureCollectionFrom(MapRouteLine.java:351)
        at com.mapbox.services.android.navigation.ui.v5.route.MapRouteLine.drawWayPoints(MapRouteLine.java:345)
        at com.mapbox.services.android.navigation.ui.v5.route.MapRouteLine.access$300(MapRouteLine.java:45)
        at com.mapbox.services.android.navigation.ui.v5.route.MapRouteLine$1.onRouteFeaturesProcessed(MapRouteLine.java:331)
        at com.mapbox.services.android.navigation.ui.v5.route.FeatureProcessingTask$1.run(FeatureProcessingTask.java:65)
        at android.os.Handler.handleCallback(Handler.java:888)
        at android.os.Handler.dispatchMessage(Handler.java:100)
        at android.os.Looper.loop(Looper.java:213)
        at android.app.ActivityThread.main(ActivityThread.java:8178)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:513)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1101)

Reason Why

This code loops thru the legs, and works... https://github.com/mapbox/mapbox-navigation-android/blob/e1f0918b6e73ceaf8bd3d1ef3886c8600289b184/libnavui-maps/src/main/java/com/mapbox/navigation/ui/maps/internal/route/line/MapboxRouteLineUtils.kt#L463

Calls this function with it = leg and 0 = index: https://github.com/mapbox/mapbox-navigation-android/blob/e1f0918b6e73ceaf8bd3d1ef3886c8600289b184/libnavui-maps/src/main/java/com/mapbox/navigation/ui/maps/internal/route/line/MapboxRouteLineUtils.kt#L486

However, if you notice the above steps supplied by the MapBox directions API, it is an empty array; so the: The key part is this: leg.steps()?.get(index)? lets dissect it... leg.steps()? <- Exists and is NOT null (good so far), but then .get(index)? since there is no 0 item in the steps array the .get crashes with the error: java.lang.IndexOutOfBoundsException: Index: 0, Size: 0 as you are trying to get a element out of a zero sized array.

Workaround

When using the MapBoxDirection Builder, pass .steps(true) into it so that it will create items in the steps array.

stale[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

abhishek1508 commented 2 years ago

Thanks for using the Mapbox Navigation SDK for Android and being a valued customer.

Mapbox will be soon deprecating any support for v0 and v1 versions of the SDK. To facilitate this transition we’re launching a new drop-in UI component into v2, equivalent to the existing NavigationView v1 in its design goals, however with a more modern and customizable API.

We plan to launch this new drop-in UI component as a Developer Preview feature in April, as part of the v2.5 series. Since you are using NavigationView with v1, we’d love to hear your feedback so that we can incorporate it ahead of a GA release.

If you’re interested in having early access to the upcoming drop-in UI for v2 and its documentation, drop a comment on this ticket or send an email to abhishek.kejriwal@mapbox.com

/cc @zugaldia @AhmerKhan1