Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

crash when user taps the done button without waiting for the whole image to download #32

Closed
mythodeia opened this issue Oct 6, 2013 · 7 comments

Comments

@mythodeia
Copy link

Hello
i experienced a crash right when the user taps on a cell image, the modal opens and the progress is being shown to download an image from the web.
if you do not wait for the whole image to download and hit the DONE button the method performCloseAnimationWithScrollView crashes when setting the resizableImageView frame size, since the imageFromView is nil.

a solution would be an if statement like this:
if (imageFromView == nil) {
// in case the user taps the DONE button without
// waiting for the whole image to download
resizableImageView.frame = CGRectZero;
}
else{
.......

if you find any better solution please share.

thanks

@eduardocallado
Copy link
Collaborator

Hey. I couldn't reproduce this crash here.
But I didn't understand one thing: how the performCloseAnimationWithScrollView: method was called, since its only called to dismiss images that was already on screen, and in this case, they are not from the web, so there is no loading. And since you said you pressed the done button while the image was loading, the only dismiss method called is dismissPhotoBrowserAnimated:.

@mythodeia
Copy link
Author

Hello
if you see inside the doneButtonPressed line 1247 there is a call for the performCloseAnimationWithScrollView.
i have uploaded a modified smaller sized sample to my dropbox. check it here:
https://dl.dropboxusercontent.com/u/34562882/IDMPhotoBrowser.zip

all you have to do is tap the cell to open the modal and immediately
either tap the done button before the image downloads
or drag the image down to dismiss it before the image downloads.

what i forgot to mention before is that it happens when calling this ...animatedFromView initializer of the IDMPhotoBrowser.
in my scenario i have a cell image that i want the animation to begin with thats why i use the animatedFromView:...

hope now you can understand where it crashes.
thanks

@Angelbear
Copy link

hello @eduardocallado ,

The problem is https://github.com/ideaismobile/IDMPhotoBrowser/blob/master/Classes/IDMPhotoBrowser.m#L385

When call the performCloseAnimationWithScrollView, UIImage imageFromView = [scrollView.photo underlyingImage]; was called, but for remote loading image, underlyingImage is nil before loadUnderlyingImageAndNotify. So float scaleFactor = imageFromView.size.width / screenWidth; got 0, and when some number divide scaleFactor, it gets NaN, which cause the problem of
*
* Terminating app due to uncaught exception 'CALayerInvalidGeometry', reason: 'CALayer position contains NaN: [160 nan]'

@mythodeia
Copy link
Author

This could be fixed with a check for nil like in my first post.
if someone has a more solid solution please share

thanks

@eduardocallado
Copy link
Collaborator

Now I get it. And I just fixed it.
Thank you guys for the help.

@mythodeia
Copy link
Author

No problem.
Glad I could be of assistance.

Thanks

Sent from my iPhone

On 8 Οκτ 2013, at 17:09, "Eduardo Callado" notifications@github.com wrote:

Now I get it. And I just fixed it.
Thank you guys for the help.


Reply to this email directly or view it on GitHub.

@iTofu
Copy link

iTofu commented Aug 2, 2018

I have the same problem and I checked the code, at -[IDMPhotoBrowser performCloseAnimationWithScrollView:] method, there are two lines:

float scaleX = senderViewOriginalFrame.size.width/scrollView.photoImageView.width;
float scaleY = senderViewOriginalFrame.size.height/scrollView.photoImageView.height;

scrollView.photoImageView.width and scrollView.photoImageView.height are both 0 when user taps the done button without waiting for the whole image to download, so it crashed.

My solution is that:

float scaleX = 0;
if (scrollView.photoImageView.width > 0) {
    scaleX = senderViewOriginalFrame.size.width/scrollView.photoImageView.width;
}
float scaleY = 0;
if (scrollView.photoImageView.height > 0) {
    scaleY = senderViewOriginalFrame.size.height/scrollView.photoImageView.height;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants