Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Crash on iOS 4.2 with Pinch-Zoom - Works in iOS 4.0 and 3.2 #73

Open
bkgoodman opened this Issue · 15 comments

6 participants

@bkgoodman

I have an app which has been running just fine under iOS 3.2 and 4.0 for a while. When I now build and run on iOS 4.2 (on either an iPhone, or iPad - actual device). The map displays and pans fine. However, when I try to pinch-zoom, I immediately throw the following exception:

*** Terminating app due to uncaught exception 'CALayerInvalidGeometry', reason: 'CALayer bounds contains NaN: [nan nan; 0 0]'

Stack backtrace is as follows:

 +[NSException raise:format:arguments:] + 68
 +[NSException raise:format:] + 34
 _ZL16CALayerSetBoundsP7CALayerRKN2CA4RectEb + 200
 -[CALayer setBounds:] + 90
 -[RMMapLayer zoomByFactor:near:] + 154
 -[RMLayerCollection zoomByFactor:near:] + 242
 -[RMMapContents zoomByFactor:near:animated:withCallback:] + 628
 -[RMMapView zoomByFactor:near:animated:] + 146
 -[RMMapView zoomByFactor:near:] + 34
 -[RMMapView touchesMoved:withEvent:] + 606
 -[UIWindow _sendTouchesForEvent:] + 334
 -[UIWindow sendEvent:] + 262
 -[UIApplication sendEvent:] + 298
 _UIApplicationHandleEvent + 5090
@andrewljohnson
Collaborator

This doesn't happen every time, but I've observed the same bug, and my stack trace is the same.

@andrewljohnson
Collaborator

We have now hacked a fix into our code for this, and we also think we know a more specific cause for this error.

Replacing the zoomByFactor function as follows will fix the bug, but it's probably not getting at the root cause:

- (void)zoomByFactor: (float) zoomFactor near:(CGPoint) pivot {
  self.position = RMScaleCGPointAboutPoint(self.position, zoomFactor, pivot);
  CGRect temp = RMScaleCGRectAboutPoint(self.bounds, zoomFactor, self.anchorPoint);
  if (temp.size.width == 0 && temp.size.height == 0) {
    RMLog(@"This woulda busted before");
  } else {
    self.bounds = temp;
  }
}

It seems to get triggered if you try and do a pinch zoom when you have an RMPath with just zero or maybe one point in it on the map. I was having trouble reproducing this bug, but then I noticed if I did a pinch zoom right after I started recording a track in my app, I could reproduce it fairly reliably.

@vyskocil
Owner

I also think it's tied to RMPath layer as andrewljohnson suggested. I saw this only when I had a path layer activated.

@hjon
Owner

If it's tied to having an RMPath, I may have some insights from RMCircle that could help. When I put together RMCircle, I did a few things differently from RMPath. It's possible that those could make a difference. I've been meaning to try them out with RMPath, but haven't taken the time yet. I'll try to take a look later today.

Does this only occur on a device? Or can it be reproduced with the iOS 4.2 Simulator as well?

@bkgoodman

Not sure if this problem happens on the simulator. Will have to check - but won't be able to for about 12 hours.

@bkgoodman

I cannot get to the point where I can run it on the simulator, because I am gated by bug #57, which also only happens under iOS 4.2.

@bkgoodman

Also - in reading the above comments, I noticed that I do have an RMPath (two, actually) which probably have zero points at this point in time. In commenting out their insertion, the crash goes away - so while the problem still exists, at least I have a work-around!


Also - I did notice that I was getting the console output under previous versions of iOS, but not the crash.

@hjon
Owner

I took a look today at RMPath, and it looks like some of the changes I made with RMCircle would remove functionality from RMPath (which I don't want to do at this point).

For now, it's probably best to use Andrew's fix.

Alternatively, I noticed that Michael had proposed some changes for RMPath in Issue 64 that may be worth trying out (#64).

@amjaliks

I get the same exception just by dragging map (not zooming). The exception occurs, when I try to move map outside constraints.
The exception occurs only on real devices (iPhone 4, iPad, both 4.2.1). In the simulator RMMapView perfectly keeps me from dragging a map outside constraints.

Stacktrace:

+[NSException raise:format:arguments:] + 68
+[NSException raise:format:] + 34
_ZL18CALayerSetPositionP7CALayerRKN2CA4Vec2IdEEb + 140
-[CALayer setPosition:] + 38
-[RMTileImage setScreenLocation:] + 92
-[RMTileImage moveBy:] + 92
-[RMTileImageSet moveBy:] + 204
-[RMMapContents moveBy:] + 84
-[RMMapView moveBy:] + 524
-[RMMapView touchesMoved:withEvent:] + 1100
-[UIWindow _sendTouchesForEvent:] + 334
-[UIWindow sendEvent:] + 262
-[UIApplication sendEvent:] + 298
_UIApplicationHandleEvent + 5090
@AngelusDarkness

Hi i want to ask, if somebody found a solution for amjaliks problem, because i have the same.

Debugging a little I found out that a NaN Value is causing the crash. On the Next Method.
Source: (RMTileImage.m)
(void) setScreenLocation: (CGRect)newScreenLocation
{
screenLocation = newScreenLocation;

if (layer != nil)
{
    // layer.frame = screenLocation;
    layer.position = screenLocation.origin;
    layer.bounds = CGRectMake(0, 0, screenLocation.size.width, screenLocation.size.height);
}

[self touch];

}

newScreenLocation it's incoming with NaN values, but I can't for now, find a way to detect them and avoid the assignation of newScreenLocation values to screenLocation, that is when app crash.

If anybody has any idea about how resolve this issue, would be very helpfully for me!

Thanks!

Edit UPDATE:

Well i found one possible solution.

On (RMMapView.m) -(void)moveBy:(CGSize)delta

Line 245: CGSize sizeRatio = CGSizeMake(XYDelta.width / delta.width, XYDelta.height / delta.height); <-- Can produce NaN values.

So, added an check after that operation, could fix the crash:

    if (delta.width == 0 || delta.height == 0)
    {
        RMLog(@"Possible NaN Value");
        return;
    }

How i'm just starting with route-me source, i don't really know if this is the best solution, but for now solve my problem. I hope, this help somebody else!

@hjon
Owner

I just added a pull request (#90) that may help this issue. I was trying to fix another issue and I don't have a device with 4.2 on it, so could someone try it out to see if that patch helps this issue?

@hjon
Owner

Actually, the other pull request (#91) I added may help, too. I believe this pull request essentially fixes the issue in a similar (but hopefully better) way to how Andrew fixed the issue (#73 (comment))

@amjaliks

Pull request #90 fix this issue for me. Tested on actual iP4 with 4.2.1.
Thanks!

P.S. I think this issue can be closed.

@amjaliks

Fixed.

@amjaliks amjaliks closed this
@vyskocil
Owner

This issue was not properly fixed, I can reproduce the crash condition when a new path layer is added on the map and is left empty, then if I zoom in/out it crash.
I propose the fix in #111

@vyskocil vyskocil reopened this
@incanus incanus referenced this issue from a commit in mapbox/mapbox-ios-sdk-legacy
@trasch trasch o Implemented the missingTilesDepth feature (issue #73), which tries …
…to take missing tiles from lower zoom levels
e306fe9
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.