Skip to content

Commit

Permalink
MOD: added catch for bad/corrupt loaded image data
Browse files Browse the repository at this point in the history
  • Loading branch information
u10int committed May 10, 2014
1 parent 9af2a76 commit 157af36
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions URBMediaFocusViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -804,6 +804,17 @@ - (void)connectionDidFinishLoading:(NSURLConnection *)connection {
else {
image = [UIImage imageWithData:self.urlData];
}

// sometimes the server can return bad or corrupt image data which will result in a crash if we don't throw an error here
if (!image) {
NSString *errorDescription = [NSString stringWithFormat:@"Bad or corrupt image data for %@", urlPath];
NSError *error = [NSError errorWithDomain:@"com.urban10.URBMediaFocusViewController" code:100 userInfo:@{NSLocalizedDescriptionKey: errorDescription}];
if ([self.delegate respondsToSelector:@selector(mediaFocusViewController:didFailLoadingImageWithError:)]) {
[self.delegate mediaFocusViewController:self didFailLoadingImageWithError:error];
}
return;
}

[self showImage:image fromRect:self.fromRect];

if ([self.delegate respondsToSelector:@selector(mediaFocusViewController:didFinishLoadingImage:)]) {
Expand Down

0 comments on commit 157af36

Please sign in to comment.