MKPolyline polylineWithCoordinates 临时崩溃,但通过 xcode 安装时不会崩溃
MKPolyline polylineWithCoordinates crashes on ad hoc but not when installed via xcode
下面的代码 运行s 当我的东西正在初始化时
CLLocationCoordinate2D outline[track.lastGeo -track.firstGeo];
CLLocationCoordinate2D upper = ((CLLocation*)track.locations[track.firstGeo]).coordinate;
CLLocationCoordinate2D lower = ((CLLocation*)track.locations[track.firstGeo]).coordinate;
int count = 0;
for (int i = track.firstGeo; i <= track.lastGeo; i++) {
CLLocation *firstLoc = [track.locations objectAtIndex:i];
outline[count++] = firstLoc.coordinate;
if([firstLoc coordinate].latitude > upper.latitude) upper.latitude = [firstLoc coordinate].latitude;
if([firstLoc coordinate].latitude < lower.latitude) lower.latitude = [firstLoc coordinate].latitude;
if([firstLoc coordinate].longitude > upper.longitude) upper.longitude = [firstLoc coordinate].longitude;
if([firstLoc coordinate].longitude < lower.longitude) lower.longitude = [firstLoc coordinate].longitude;
}
_outline = [MKPolyline polylineWithCoordinates:outline count:count -1];
并且通过 xcode 部署时 运行 没问题。
但是当我通过 itunes ad hoc 安装应用程序时,它崩溃了
Exception Type: EXC_BAD_ACCESS (SIGSEGV)
Exception Subtype: KERN_INVALID_ADDRESS at 0x40480b3508f648cf
Triggered by Thread: 0
Filtered syslog:
None found
Thread 0 name: Dispatch queue: com.apple.main-thread
Thread 0 Crashed:
0 MapKit 0x000000018de19484 -[MKMultiPoint _wrapAroundTheDateline:count:] + 108
1 MapKit 0x000000018de195d8 -[MKMultiPoint _setCoordinates:count:] + 184
2 MapKit 0x000000018de195d8 -[MKMultiPoint _setCoordinates:count:] + 184
3 MapKit 0x000000018de13a74 +[MKPolyline polylineWithCoordinates:count:] + 84
谁能想出这是为什么?
- 这些位置确实存在 xcode 运行 的安装就好了
- 我没有更改 xcode 中的任何 debug/release 选项,都是标准的
- 它在不同的设备上崩溃,但只有在特定情况下才会崩溃
因为 MapKit 不是开源的我不知道是什么
[MKMultiPoint _wrapAroundTheDateline:count:]
在那里崩溃或为什么崩溃
编辑 1
归结为 MKMultiPoint 试图 malloc 的方式太多 space。
malloc: *** mach_vm_map(size=2405744640) failed (error code=3)
有没有可能是XCode的优化级别导致的?当 运行 进行调试时,它没有发生,所以也许为了加快速度,发布代码被弄乱以利用 space 来提高速度,从而导致这里出现问题?!
我所做的只是创建一条具有大约 1000 个坐标的折线(实际长度可能为 5 公里)!
这是调试有多么困难的另一个完美例子。
罪魁祸首是
CLLocationCoordinate2D outline[track.lastGeo -track.firstGeo];
有人会认为这样分配一个数组是可行的。然而,出于某种原因,xcode 的代码优化器完全搞砸了。
太糟糕了
int count = 0;
这个整数值会在 for 循环期间和之后发生变化。所以 Polyline 被赋予了一个疯狂的大整数,从而超出了内存限制。
即使声明 int const
也无济于事,不知何故内存地址被弄乱了并且一直被覆盖。仅启用代码优化,因此仅使用发布构建方案,不使用调试。
在 MKPolyline 之前放置一个 NSLog(@"%d", count)
一次尝试解决了它。将它放在折线之后不会。彻头彻尾的疯狂。
将 int
换成更合规的 NSUInteger
也无济于事。
我最终得到了这个
const NSUInteger size = (track.lastGeo -track.firstGeo +1);
CLLocationCoordinate2D *outline = calloc(size, sizeof(CLLocationCoordinate2D));
下面的代码 运行s 当我的东西正在初始化时
CLLocationCoordinate2D outline[track.lastGeo -track.firstGeo];
CLLocationCoordinate2D upper = ((CLLocation*)track.locations[track.firstGeo]).coordinate;
CLLocationCoordinate2D lower = ((CLLocation*)track.locations[track.firstGeo]).coordinate;
int count = 0;
for (int i = track.firstGeo; i <= track.lastGeo; i++) {
CLLocation *firstLoc = [track.locations objectAtIndex:i];
outline[count++] = firstLoc.coordinate;
if([firstLoc coordinate].latitude > upper.latitude) upper.latitude = [firstLoc coordinate].latitude;
if([firstLoc coordinate].latitude < lower.latitude) lower.latitude = [firstLoc coordinate].latitude;
if([firstLoc coordinate].longitude > upper.longitude) upper.longitude = [firstLoc coordinate].longitude;
if([firstLoc coordinate].longitude < lower.longitude) lower.longitude = [firstLoc coordinate].longitude;
}
_outline = [MKPolyline polylineWithCoordinates:outline count:count -1];
并且通过 xcode 部署时 运行 没问题。 但是当我通过 itunes ad hoc 安装应用程序时,它崩溃了
Exception Type: EXC_BAD_ACCESS (SIGSEGV)
Exception Subtype: KERN_INVALID_ADDRESS at 0x40480b3508f648cf
Triggered by Thread: 0
Filtered syslog:
None found
Thread 0 name: Dispatch queue: com.apple.main-thread
Thread 0 Crashed:
0 MapKit 0x000000018de19484 -[MKMultiPoint _wrapAroundTheDateline:count:] + 108
1 MapKit 0x000000018de195d8 -[MKMultiPoint _setCoordinates:count:] + 184
2 MapKit 0x000000018de195d8 -[MKMultiPoint _setCoordinates:count:] + 184
3 MapKit 0x000000018de13a74 +[MKPolyline polylineWithCoordinates:count:] + 84
谁能想出这是为什么?
- 这些位置确实存在 xcode 运行 的安装就好了
- 我没有更改 xcode 中的任何 debug/release 选项,都是标准的
- 它在不同的设备上崩溃,但只有在特定情况下才会崩溃
因为 MapKit 不是开源的我不知道是什么
[MKMultiPoint _wrapAroundTheDateline:count:]
在那里崩溃或为什么崩溃
编辑 1
归结为 MKMultiPoint 试图 malloc 的方式太多 space。
malloc: *** mach_vm_map(size=2405744640) failed (error code=3)
有没有可能是XCode的优化级别导致的?当 运行 进行调试时,它没有发生,所以也许为了加快速度,发布代码被弄乱以利用 space 来提高速度,从而导致这里出现问题?!
我所做的只是创建一条具有大约 1000 个坐标的折线(实际长度可能为 5 公里)!
这是调试有多么困难的另一个完美例子。
罪魁祸首是
CLLocationCoordinate2D outline[track.lastGeo -track.firstGeo];
有人会认为这样分配一个数组是可行的。然而,出于某种原因,xcode 的代码优化器完全搞砸了。 太糟糕了
int count = 0;
这个整数值会在 for 循环期间和之后发生变化。所以 Polyline 被赋予了一个疯狂的大整数,从而超出了内存限制。
即使声明 int const
也无济于事,不知何故内存地址被弄乱了并且一直被覆盖。仅启用代码优化,因此仅使用发布构建方案,不使用调试。
在 MKPolyline 之前放置一个 NSLog(@"%d", count)
一次尝试解决了它。将它放在折线之后不会。彻头彻尾的疯狂。
将 int
换成更合规的 NSUInteger
也无济于事。
我最终得到了这个
const NSUInteger size = (track.lastGeo -track.firstGeo +1);
CLLocationCoordinate2D *outline = calloc(size, sizeof(CLLocationCoordinate2D));