mapbox / mapbox-navigation-ios

Turn-by-turn navigation logic and UI in Swift on iOS
https://docs.mapbox.com/ios/navigation/
Other
859 stars 310 forks source link

EXC_BAD_ACCESS memory issue in Router #4590

Closed faliinitse closed 2 days ago

faliinitse commented 7 months ago

Mapbox is giving an EXC_BAD_ACCESS error in the Router Class. This issue is strange and difficult to debug. Let me explain a little about our app. We have an app with blocks, each containing many trips. The app is working fine for all the blocks and their trips. However, for just one block and its trip, the app is crashing when rerouting occurs. We don't know why it's crashing only for that particular trip of a block, and only in the case of rerouting. I am attaching a screenshot; perhaps you can guide us on how to track this bug. I even checked the route data by converting it into plain json string; there is not much change when it first loads and when the reroute occurs. Even all the properties routeData,routeRequest and responseOrigin have data but as soon as it reach the line 75 it gives this error. So, I am confused about what the exact issue is. Just for your information, we are loading a custom route and not using Mapbox Direction API for loading routes. Routes are coming from our own server.

Screenshot 2024-01-19 at 16 16 06
baleboy commented 7 months ago

Could you share a full log that includes the error?

faliinitse commented 7 months ago

Could you share a full log that includes the error?

Here is the log file of crash

logFile.txt

faliinitse commented 7 months ago

Hi, @baleboy , do you need anything else regarding this issue to be solved? We are stuck for our next release, and this issue is a major roadblock for us. Could you please help me in this case?

kried commented 6 months ago

Hi @faliinitse Could you please share the Navigation and Directions SDK versions you are using? Is the problem reproducing consistently during the reroute?

Would it be possible to share the route response that cause the crash?

faliinitse commented 6 months ago

Hi @kried

Following is the screenshot of my podfile.lock

Screenshot 2024-02-13 at 09 14 13

Here is the routeResponse output as p routeResponse and po routeResponse for the initial load when no crash has occurred, and after rerouting when the actual crash is occurring.

First load when no crash occurred poResponseFirstLoad.txt pResponseFirstLoad.txt

After rerouting when crash occurred.

poResponseAfterRerouting.txt PResponseAfterRerouting.txt

I also converted the routeData to plain JSON string; it may also help in identifying the crash.

routeDataJsonAfterRerouting.txt routeDataJsonFirstLoad.txt

faliinitse commented 6 months ago

Is the problem reproducing consistently during the reroute?

Yes, it always crashes when rerouting occurs for one of our trips. For all other trips, it works fine. However, it only crashes during rerouting for this particular trip. I've shared the JSON data and routeResponse. I hope it will help to find the bug.

faliinitse commented 5 months ago

Hi @kried,

Any update on this issue? Our new release is stalled because of this problem. Could you please provide an update if you've found anything based on the data I provided? I would highly appreciate it if you could respond to my comment.

kried commented 5 months ago

Hi @faliinitse

Thank you for the recorded data, we were able to reproduce the problem. We will fix the crash in upcoming SDK releases.

But the response routeDataJsonAfterRerouting.txt seems to be incorrect. It contains the 11 waypoints, but only 9 legs instead of 10. The SDK definitely should not crash in such cases, but the waypoints list should be decreased in the response. After looking at the legs in the response, it seems like the last waypoint is redundant.

So the response.json with the removed last waypoint does not cause the crash.

Could you please answer if you received this response from Directions API or did you use the custom routing provider? Or did you manually change some properties in the response?

faliinitse commented 5 months ago

Hi @kried,

Thank you for working on this issue and fixing it. Could you please inform us when you implement this fix in the next version so that I can retest it?

Regarding your second point, we have our own endpoint from which we retrieve data, and we do not use the DirectionAPI. I will communicate this to our backend developer so that they can address the issue accordingly and we also fix this.

One last point to consider is this that this issue also affects the Android side. Should we open a new ticket for Android, or will the fix apply to both platforms in a future version?

kried commented 5 months ago

@faliinitse This exact crash won't happen on Android, but please validate the response to the Directions API response scheme to avoid incorrect response parsing.

E.g. the response does not contain the required field name for the Waypoint object in the response and there is no code at the top level of the response.

faliinitse commented 2 months ago

Hi @kried, could you please let us know if the following crash has been fixed in any new version that has been released?

kried commented 2 months ago

Hi @faliinitse

The fix should be available in v2.18.0 with NavigationNative v204.0.1