enormego / PhotoViewer

Quick PhotoViewer for the iPhone. Built upon our other reliable libraries: EGOImageLoading and EGOCache.
http://developers.enormego.com
660 stars 141 forks source link

Terminating app due to uncaught exception 'CALayerInvalidGeometry' #11

Closed MrMoins closed 4 years ago

MrMoins commented 13 years ago

Hi, I'm having some trouble with EGOPhotoImageView (I think), see there crash log below. I'm using iOS 4.2.1 GM on iPhone 4. Same code works on 3.1.3.

2010-12-01 20:36:30.293 myapp[1650:307] EGO PAGE INDEX LIB CONTROLLER 0 2010-12-01 20:36:30.454 myapp[1650:307] * Terminating app due to uncaught exception 'CALayerInvalidGeometry', reason: 'CALayer position contains NaN: [nan nan]' * Call stack at first throw: ( 0 CoreFoundation 0x33ac0987 exceptionPreprocess + 114 1 libobjc.A.dylib 0x3347b49d objc_exception_throw + 24 2 CoreFoundation 0x33ac07c9 +[NSException raise:format:arguments:] + 68 3 CoreFoundation 0x33ac0803 +[NSException raise:format:] + 34 4 QuartzCore 0x34104229 _ZL18CALayerSetPositionP7CALayerRKN2CA4Vec2IdEEb + 140 5 QuartzCore 0x34104197 -[CALayer setPosition:] + 38 6 QuartzCore 0x341040e3 -[CALayer setFrame:] + 390 7 UIKit 0x320670e9 -[UIView(Geometry) setFrame:] + 188 8 UIKit 0x320b2bd1 -[UIScrollView setFrame:] + 420 9 myapp 0x0006522f -[EGOPhotoImageView killScrollViewZoom] + 646 10 myapp 0x00060861 -[EGOPhotoViewController moveToPhotoAtIndex:animated:] + 812 11 myapp 0x0005e749 -[EGOPhotoViewController viewWillAppear:] + 1496 12 UIKit 0x320ac637 -[UINavigationController _startTransition:fromViewController:toViewController:] + 610 13 UIKit 0x320ac35f -[UINavigationController _startDeferredTransitionIfNeeded] + 182 14 UIKit 0x320a00c5 -[UINavigationController pushViewController:transition:forceImmediate:] + 640 15 UIKit 0x3209fe3b -[UINavigationController pushViewController:animated:] + 34 16 myapp 0x000533c3 -[NDetailViewController goToDisplayPictures:] + 2278 17 myapp 0x0005767b -[PhotosView tap:] + 154 18 myapp 0x00040e93 -[TapImageView touchesBegan:withEvent:] + 66 19 UIKit 0x320641e9 _UIGestureRecognizerSortAndSendDelayedTouches + 2200 20 UIKit 0x320638b5 _UIGestureRecognizerUpdateObserver + 696 21 CoreFoundation 0x33a50c59 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION + 16 22 CoreFoundation 0x33a50acd CFRunLoopDoObservers + 412 23 CoreFoundation 0x33a480cb CFRunLoopRun + 854 24 CoreFoundation 0x33a47c87 CFRunLoopRunSpecific + 230 25 CoreFoundation 0x33a47b8f CFRunLoopRunInMode + 58 26 GraphicsServices 0x33b0e4ab GSEventRunModal + 114 27 GraphicsServices 0x33b0e557 GSEventRun + 62 28 UIKit 0x32099329 -[UIApplication _run] + 412 29 UIKit 0x32096e93 UIApplicationMain + 670 30 myapp 0x00002bc7 main + 70 31 myapp 0x00002b7c start + 40 ) terminate called after throwing an instance of 'NSException'


I've a loop to populate an array of photo :

        MyPhoto * photo = [[MyPhoto alloc] initWithImageURL:[NSURL URLWithString:@"photo-url-here"] name:@"photo-name-here"];
        [imageViewArray addObject:photo];

and after this loop :

MyPhotoSource *source = [[MyPhotoSource alloc] initWithPhotos:imageViewArray];
EGOPhotoViewController * photoController = [[EGOPhotoViewController alloc] initWithPhotoSource:source];

and I after I do the pushViewController.

devindoty commented 13 years ago

What is the frame of navigation controller when the photo view controller is pushed on the stack? It seems like the view hierarchy is getting incorrect values.

MrMoins commented 13 years ago

appDelegate = (myappAppDelegate *)[[UIApplication sharedApplication] delegate]; [appDelegate.navController pushViewController:photoController animated:YES];

sorry I copy/paste snippet of code that I don't wrote and don't really understand ...

MrMoins commented 13 years ago

if I move : appDelegate = (myappAppDelegate *)[[UIApplication sharedApplication] delegate]; to the viewDidLoad of my current controler then I've no errors, but, I'm not pushed to the photoController and the app doesn't crash...

solydzajs commented 13 years ago

I had similar issue today and I did a quick fix in EGOPhotoImageView.m, basically the problems seems to be NaN number that are created when dividing number by 0.

so just make sure to catch that case and try not to divide by 0 if factor for some reason is 0:

in (CGSize)sizeForPopover

    CGFloat newWidth = factor ? popoverSize.width / factor : 0;
    CGFloat newHeight = factor ? popoverSize.height / factor : 0;

in (void)killScrollViewZoom

CGFloat newWidth = factor ? self.imageView.image.size.width / factor : 0;
CGFloat newHeight = factor ? self.imageView.image.size.height / factor : 0;

in (void)layoutScrollViewAnimated:(BOOL)animated

CGFloat newWidth = factor ? self.imageView.image.size.width / factor : 0;
CGFloat newHeight = factor ? self.imageView.image.size.height / factor : 0;
AdamSwinden commented 13 years ago

I had the same issue, found it was being caused by the self.imageView.image on EGOPhotoImageView was nil due to the default placeholder image being named incorrectly. EGOPhotoGlobal had the following statement:

#define kEGOPhotoLoadingPlaceholder [UIImage imageNamed:@"photo_placeholder.png"]

...however the file was called egopv_photo_placeholder.png.

This seems to have now been fixed.

solydzajs commented 13 years ago

Right, that might be it.