gpt4 book ai didi

ios - Skobbler didFinishRouteCalculationWithInfo 数组异常

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:04:47 25 4
gpt4 key购买 nike

在 iOS 中使用 Skobbler map 时出现异常。似乎是导致无效数组访问的并发异常,但由于 Skobbler 提供的代码存在问题,因此不确定如何以最佳方式修复其损坏的代码。

请参阅标记为“HERE!!!”的行在下面的代码中:

文件:SKTNavigationManager.m

- (void)routingService:(SKRoutingService *)routingService didFinishRouteCalculationWithInfo:(SKRouteInformation *)routeInformation {
dispatch_async(dispatch_get_main_queue(), ^{
__block BOOL routeExists = NO;
[_calculatedRoutes enumerateObjectsUsingBlock:^(SKRouteInformation *obj, NSUInteger idx, BOOL *stop) {
if (routeInformation.routeID == obj.routeID) {
routeExists = YES;
*stop = YES;
}
}];

if (!routeInformation.corridorIsDownloaded || routeExists || _calculatedRoutes.count == _configuration.numberOfRoutes) {
return;
}

//are we still calculating the routes?
if ([self hasState:SKTNavigationStateCalculatingRoute]) {
[_calculatedRoutes addObject:routeInformation];

//stop progress for the calculated route
SKTRouteProgressView *progressVIew = _mainView.calculatingRouteView.progressViews[_calculatedRoutes.count - 1]; // HERE!!!
[progressVIew startProgress];

//show the info for the calculated route
[_mainView.calculatingRouteView showInfoViewAtIndex:_calculatedRoutes.count - 1];
[self updateCalculatedRouteInformationAtIndex:_calculatedRoutes.count - 1];

//start progress for next route if needed
if (_calculatedRoutes.count < _mainView.calculatingRouteView.numberOfRoutes) {
SKTRouteProgressView *progressVIew = _mainView.calculatingRouteView.progressViews[_calculatedRoutes.count];
[progressVIew startProgress];
}

if (!_selectedRoute) {
_selectedRoute = routeInformation;
[SKRoutingService sharedInstance].mainRouteId = _selectedRoute.routeID;
[self zoomOnSelectedRoute];
_mainView.calculatingRouteView.selectedInfoIndex = 0;
_mainView.calculatingRouteView.startButton.hidden = NO;
}
} else if ([self hasState:SKTNavigationStateRerouting]) { //nope, we're being rerouted
_selectedRoute = routeInformation;
_navigationInfo.currentDTA = _selectedRoute.distance;
[self updateDTA];
_navigationInfo.currentETA = _selectedRoute.estimatedTime;
[self updateETA];
[SKRoutingService sharedInstance].mainRouteId = _selectedRoute.routeID;
[NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(removeReroutingState) object:nil];
[self performSelector:@selector(removeReroutingState) withObject:nil afterDelay:kMinReroutingDisplayTime];
}
});
}

报告的异常是...

8   libobjc.A.dylib - objc_exception_throw + 332 (objc-exception.mm:568)
9 CoreFoundation - [__NSArrayM objectAtIndex:] + 240 (NSArray.m:410)
10 MyApp -[SKTNavigationManager routingService:didFinishRouteCalculationWithInfo:]_block_invoke + 676 (SKTNavigationManager.m:463)

有什么想法吗?我可以在从 progressViews 数组读取之前检查 _calculatedRoutes 的大小,但我遇到的问题是在访问两者的行之后有额外的代码。换句话说,我可以避开这条线,但我该如何修复该方法才能正常工作?

最佳答案

SKTNavigationManager(以及整个 SDKTools 项目)中的代码作为开放代码提供——它不是 SDK 本身的一部分,而是构成一些演示代码/帮助程序类,可以帮助您解决常见的场景(构建一个简单的导航 UI ,处理离线 map 等)。

一些开发人员将此代码用作文档,其他开发人员在他们的项目中“按原样”使用它,其他开发人员从它开始并根据自己的喜好对其进行自定义。

在你的特殊情况下,我不确定你是如何到达这种不一致状态的(使用 Vanilla 代码,在演示项目中我无法复制它) - 如果你认为你有并发问题,请随意插入额外的检查或同步机制。

关于ios - Skobbler didFinishRouteCalculationWithInfo 数组异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38438266/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com