MKPolyline polylineWithCoordinates crashes on ad hoc but not when installed via xcode
<p>The following code runs when my stuff is being initialized</p>

<pre><code>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 &lt;= track.lastGeo; i++) {

    CLLocation *firstLoc = [track.locations objectAtIndex:i];

    outline[count++] = firstLoc.coordinate;

    if([firstLoc coordinate].latitude &gt; upper.latitude) upper.latitude = [firstLoc coordinate].latitude;
    if([firstLoc coordinate].latitude &lt; lower.latitude) lower.latitude = [firstLoc coordinate].latitude;
    if([firstLoc coordinate].longitude &gt; upper.longitude) upper.longitude = [firstLoc coordinate].longitude;
    if([firstLoc coordinate].longitude &lt; lower.longitude) lower.longitude = [firstLoc coordinate].longitude;
}

_outline = [MKPolyline polylineWithCoordinates:outline count:count -1];
</code></pre>

<p>and it runs fine when deployed via xcode.
But when i install the app via itunes ad hoc, it crashes with</p>

<pre><code>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
</code></pre>

<p>Can anyone think of a reason why that is ?</p>

<ul>
<li>the locations do exist as an install with xcode runs just fine</li>
<li>i didnt change any debug/release options in xcode, all is standard</li>
<li>it crashes on different devices, but only when ad hoc</li>
</ul>

<p>Because MapKit isn't open source i have no idea what</p>

<pre><code>[MKMultiPoint _wrapAroundTheDateline:count:]
</code></pre>

<p>does or why it crashes there</p>

<p><strong>EDIT 1</strong></p>

<p>It boils down to MKMultiPoint trying to malloc way too much space.</p>

<pre><code> malloc: *** mach_vm_map(size=2405744640) failed (error code=3)
</code></pre>

<p>Is it possible that the optimization level of XCode causes this ? When run with debug it is not happening, so maybe to speed things up the release code is messed up to utilize space to gain speed and thus cause the issue here ?!</p>

<p>All i am doing is creating a Polyline with about 1000 coordinates (real life length of maybe 5 km)!</p>