Skip to content

Commit

Permalink
Fix a possible crash that could happen when displaying the route with…
Browse files Browse the repository at this point in the history
… the same source, midpoint, and destination (#4576)

* Fix a possible crash that could happen when displaying the route with the same source, midpoint, and destination
  • Loading branch information
kried authored Dec 22, 2023
1 parent 081496a commit 42a7c7b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@

### Routing

* `NavigationRouteOptions` and `NavigationMatchOptions` no longer include `.numericCongestionLevel` attribute by default for profiles other than `.automobileAvoidingTraffic`.
* `NavigationRouteOptions` and `NavigationMatchOptions` no longer include `.numericCongestionLevel` attribute by default for profiles other than `.automobileAvoidingTraffic`. ([#4564](https://github.com/mapbox/mapbox-navigation-ios/pull/4564))

### Map

* Fixed a possible crash that could happen when displaying the route with the same source, midpoint, and destination. ([#4576](https://github.com/mapbox/mapbox-navigation-ios/pull/4576))

### Other changes

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ extension NavigationMapView {
gradientStops[0.0] = associatedFeatureColor

if index + 1 < routeLineFeatures.count {
let segmentEndPercentTraveled = distanceTraveled / routeDistance
let segmentEndPercentTraveled = (routeDistance > 0.0) ? distanceTraveled / routeDistance : 0
var currentGradientStop = lineSettings.isSoft ? segmentEndPercentTraveled - stopGap : Double(CGFloat(segmentEndPercentTraveled).nextDown)
currentGradientStop = min(max(currentGradientStop, 0.0), 1.0)
gradientStops[currentGradientStop] = associatedFeatureColor
Expand All @@ -367,7 +367,7 @@ extension NavigationMapView {
if associatedFeatureColor == lastRecordSegment.1 {
gradientStops[lastRecordSegment.0] = nil
} else {
let segmentStartPercentTraveled = distanceTraveled / routeDistance
let segmentStartPercentTraveled = (routeDistance > 0.0) ? distanceTraveled / routeDistance : 0
var currentGradientStop = lineSettings.isSoft ? segmentStartPercentTraveled + stopGap : Double(CGFloat(segmentStartPercentTraveled).nextUp)
currentGradientStop = min(max(currentGradientStop, 0.0), 1.0)
gradientStops[currentGradientStop] = associatedFeatureColor
Expand All @@ -379,14 +379,14 @@ extension NavigationMapView {
if associatedFeatureColor == lastRecordSegment.1 {
gradientStops[lastRecordSegment.0] = nil
} else {
let segmentStartPercentTraveled = distanceTraveled / routeDistance
let segmentStartPercentTraveled = (routeDistance > 0.0) ? distanceTraveled / routeDistance : 0
var currentGradientStop = lineSettings.isSoft ? segmentStartPercentTraveled + stopGap : Double(CGFloat(segmentStartPercentTraveled).nextUp)
currentGradientStop = min(max(currentGradientStop, 0.0), 1.0)
gradientStops[currentGradientStop] = associatedFeatureColor
}

distanceTraveled = distanceTraveled + distance
let segmentEndPercentTraveled = distanceTraveled / routeDistance
let segmentEndPercentTraveled = (routeDistance > 0.0) ? distanceTraveled / routeDistance : 0
var currentGradientStop = lineSettings.isSoft ? segmentEndPercentTraveled - stopGap : Double(CGFloat(segmentEndPercentTraveled).nextDown)
currentGradientStop = min(max(currentGradientStop, 0.0), 1.0)
gradientStops[currentGradientStop] = associatedFeatureColor
Expand Down
8 changes: 5 additions & 3 deletions Sources/MapboxNavigation/NavigationMapView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -764,9 +764,11 @@ open class NavigationMapView: UIView {
let gradientStops = routeLineCongestionGradient(route,
congestionFeatures: congestionFeatures,
isSoft: crossfadesCongestionSegments)
defaultLineLayer.lineGradient = .expression((Expression.routeLineGradientExpression(gradientStops,
lineBaseColor: trafficUnknownColor,
isSoft: crossfadesCongestionSegments)))
defaultLineLayer.lineGradient = .expression(
(Expression.routeLineGradientExpression(gradientStops,
lineBaseColor: trafficUnknownColor,
isSoft: crossfadesCongestionSegments))
)
} else {
if showsCongestionForAlternativeRoutes {
let gradientStops = routeLineCongestionGradient(route,
Expand Down

0 comments on commit 42a7c7b

Please sign in to comment.