Skip to content
This repository has been archived by the owner on Apr 6, 2020. It is now read-only.

fix: various crashes from crash reporter #216

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions QBImagePicker/QBAlbumsViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -195,39 +195,39 @@ - (UIImage *)placeholderImageWithSize:(CGSize)size
UIGraphicsBeginImageContext(size);
CGContextRef context = UIGraphicsGetCurrentContext();

UIColor *backgroundColor = [UIColor colorWithRed:(239.0 / 255.0) green:(239.0 / 255.0) blue:(244.0 / 255.0) alpha:1.0];
UIColor *iconColor = [UIColor colorWithRed:(179.0 / 255.0) green:(179.0 / 255.0) blue:(182.0 / 255.0) alpha:1.0];
UIColor *backgroundColor = [UIColor colorWithRed:(239.0f / 255.0f) green:(239.0f / 255.0f) blue:(244.0f / 255.0f) alpha:1.0f];
UIColor *iconColor = [UIColor colorWithRed:(179.0f / 255.0f) green:(179.0f / 255.0f) blue:(182.0f / 255.0f) alpha:1.0f];

// Background
CGContextSetFillColorWithColor(context, [backgroundColor CGColor]);
CGContextFillRect(context, CGRectMake(0, 0, size.width, size.height));

// Icon (back)
CGRect backIconRect = CGRectMake(size.width * (16.0 / 68.0),
size.height * (20.0 / 68.0),
size.width * (32.0 / 68.0),
size.height * (24.0 / 68.0));
CGRect backIconRect = CGRectMake(size.width * (16.0f / 68.0f),
size.height * (20.0f / 68.0f),
size.width * (32.0f / 68.0f),
size.height * (24.0f / 68.0f));

CGContextSetFillColorWithColor(context, [iconColor CGColor]);
CGContextFillRect(context, backIconRect);

CGContextSetFillColorWithColor(context, [backgroundColor CGColor]);
CGContextFillRect(context, CGRectInset(backIconRect, 1.0, 1.0));
CGContextFillRect(context, CGRectInset(backIconRect, 1.0f, 1.0f));

// Icon (front)
CGRect frontIconRect = CGRectMake(size.width * (20.0 / 68.0),
size.height * (24.0 / 68.0),
size.width * (32.0 / 68.0),
size.height * (24.0 / 68.0));
CGRect frontIconRect = CGRectMake(size.width * (20.0f / 68.0f),
size.height * (24.0f / 68.0f),
size.width * (32.0f / 68.0f),
size.height * (24.0f / 68.0f));

CGContextSetFillColorWithColor(context, [backgroundColor CGColor]);
CGContextFillRect(context, CGRectInset(frontIconRect, -1.0, -1.0));
CGContextFillRect(context, CGRectInset(frontIconRect, -1.0f, -1.0f));

CGContextSetFillColorWithColor(context, [iconColor CGColor]);
CGContextFillRect(context, frontIconRect);

CGContextSetFillColorWithColor(context, [backgroundColor CGColor]);
CGContextFillRect(context, CGRectInset(frontIconRect, 1.0, 1.0));
CGContextFillRect(context, CGRectInset(frontIconRect, 1.0f, 1.0f));

UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
Expand Down Expand Up @@ -276,7 +276,7 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
{
QBAlbumCell *cell = [tableView dequeueReusableCellWithIdentifier:@"AlbumCell" forIndexPath:indexPath];
cell.tag = indexPath.row;
cell.borderWidth = 1.0 / [[UIScreen mainScreen] scale];
cell.borderWidth = 1.0f / [[UIScreen mainScreen] scale];

// Thumbnail
PHAssetCollection *assetCollection = self.assetCollections[indexPath.row];
Expand Down
34 changes: 23 additions & 11 deletions QBImagePicker/QBAssetsViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -300,12 +300,12 @@ - (void)updateCachedAssets

// The preheat window is twice the height of the visible rect
CGRect preheatRect = self.collectionView.bounds;
preheatRect = CGRectInset(preheatRect, 0.0, -0.5 * CGRectGetHeight(preheatRect));
preheatRect = CGRectInset(preheatRect, 0.0f, -0.5f * CGRectGetHeight(preheatRect));

// If scrolled by a "reasonable" amount...
CGFloat delta = ABS(CGRectGetMidY(preheatRect) - CGRectGetMidY(self.previousPreheatRect));

if (delta > CGRectGetHeight(self.collectionView.bounds) / 3.0) {
if (delta > CGRectGetHeight(self.collectionView.bounds) / 3.0f) {
// Compute the assets to start caching and to stop caching
NSMutableArray *addedIndexPaths = [NSMutableArray array];
NSMutableArray *removedIndexPaths = [NSMutableArray array];
Expand Down Expand Up @@ -411,7 +411,10 @@ - (void)photoLibraryDidChange:(PHChange *)changeInstance

NSIndexSet *changedIndexes = [collectionChanges changedIndexes];
if ([changedIndexes count]) {
[self.collectionView reloadItemsAtIndexPaths:[changedIndexes qb_indexPathsFromIndexesWithSection:0]];
// Fatal Exception: NSInternalInconsistencyException attempt to delete and reload the same index path
NSMutableIndexSet *changedWithoutRemovalsIndexes = [changedIndexes mutableCopy];
[changedWithoutRemovalsIndexes removeIndexes:removedIndexes];
[self.collectionView reloadItemsAtIndexPaths:[changedWithoutRemovalsIndexes qb_indexPathsFromIndexesWithSection:0]];
}
} completion:NULL];
}
Expand Down Expand Up @@ -521,26 +524,29 @@ - (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView
} else {
format = NSLocalizedStringFromTableInBundle(@"assets.footer.photos-and-videos", @"QBImagePicker", bundle, nil);
}

label.text = [NSString stringWithFormat:format, numberOfPhotos, numberOfVideos];

// Fatal Exception: NSInvalidArgumentException *** -[NSPlaceholderString initWithString:]: nil argument
label.text = [NSString stringWithFormat:format ?: @"", numberOfPhotos, numberOfVideos];
}
break;

case QBImagePickerMediaTypeImage:
{
NSString *key = (numberOfPhotos == 1) ? @"assets.footer.photo" : @"assets.footer.photos";
NSString *format = NSLocalizedStringFromTableInBundle(key, @"QBImagePicker", bundle, nil);

label.text = [NSString stringWithFormat:format, numberOfPhotos];

// Fatal Exception: NSInvalidArgumentException *** -[NSPlaceholderString initWithString:]: nil argument
label.text = [NSString stringWithFormat:format ?: @"", numberOfPhotos];
}
break;

case QBImagePickerMediaTypeVideo:
{
NSString *key = (numberOfVideos == 1) ? @"assets.footer.video" : @"assets.footer.videos";
NSString *format = NSLocalizedStringFromTableInBundle(key, @"QBImagePicker", bundle, nil);

label.text = [NSString stringWithFormat:format, numberOfVideos];

// Fatal Exception: NSInvalidArgumentException *** -[NSPlaceholderString initWithString:]: nil argument
label.text = [NSString stringWithFormat:format ?: @"", numberOfVideos];
}
break;
}
Expand Down Expand Up @@ -655,8 +661,14 @@ - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollection
} else {
numberOfColumns = self.imagePickerController.numberOfColumnsInLandscape;
}

CGFloat width = (CGRectGetWidth(self.view.frame) - 2.0 * (numberOfColumns - 1)) / numberOfColumns;

CGFloat width = (CGRectGetWidth(self.view.frame) - 2.0f * (numberOfColumns - 1)) / numberOfColumns;

// Fatal Exception: NSInternalInconsistencyException negative sizes are not supported in the flow layout
// The width and height of the specified item. Both values must be greater than 0.
if (width <= 0) {
width = 1.0f;
}

return CGSizeMake(width, width);
}
Expand Down
16 changes: 8 additions & 8 deletions QBImagePicker/QBCheckmarkView.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,18 @@ - (void)awakeFromNib
[super awakeFromNib];

// Set default values
self.borderWidth = 1.0;
self.checkmarkLineWidth = 1.2;
self.borderWidth = 1.0f;
self.checkmarkLineWidth = 1.2f;

self.borderColor = [UIColor whiteColor];
self.bodyColor = [UIColor colorWithRed:(20.0 / 255.0) green:(111.0 / 255.0) blue:(223.0 / 255.0) alpha:1.0];
self.bodyColor = [UIColor colorWithRed:(20.0f / 255.0f) green:(111.0f / 255.0f) blue:(223.0f / 255.0f) alpha:1.0f];
self.checkmarkColor = [UIColor whiteColor];

// Set shadow
self.layer.shadowColor = [[UIColor grayColor] CGColor];
self.layer.shadowOffset = CGSizeMake(0, 0);
self.layer.shadowOpacity = 0.6;
self.layer.shadowRadius = 2.0;
self.layer.shadowOpacity = 0.6f;
self.layer.shadowRadius = 2.0f;
}

- (void)drawRect:(CGRect)rect
Expand All @@ -43,9 +43,9 @@ - (void)drawRect:(CGRect)rect
UIBezierPath *checkmarkPath = [UIBezierPath bezierPath];
checkmarkPath.lineWidth = self.checkmarkLineWidth;

[checkmarkPath moveToPoint:CGPointMake(CGRectGetWidth(self.bounds) * (6.0 / 24.0), CGRectGetHeight(self.bounds) * (12.0 / 24.0))];
[checkmarkPath addLineToPoint:CGPointMake(CGRectGetWidth(self.bounds) * (10.0 / 24.0), CGRectGetHeight(self.bounds) * (16.0 / 24.0))];
[checkmarkPath addLineToPoint:CGPointMake(CGRectGetWidth(self.bounds) * (18.0 / 24.0), CGRectGetHeight(self.bounds) * (8.0 / 24.0))];
[checkmarkPath moveToPoint:CGPointMake(CGRectGetWidth(self.bounds) * (6.0f / 24.0f), CGRectGetHeight(self.bounds) * (12.0f / 24.0f))];
[checkmarkPath addLineToPoint:CGPointMake(CGRectGetWidth(self.bounds) * (10.0f / 24.0f), CGRectGetHeight(self.bounds) * (16.0f / 24.0f))];
[checkmarkPath addLineToPoint:CGPointMake(CGRectGetWidth(self.bounds) * (18.0f / 24.0f), CGRectGetHeight(self.bounds) * (8.0f / 24.0f))];

[self.checkmarkColor setStroke];
[checkmarkPath stroke];
Expand Down
4 changes: 2 additions & 2 deletions QBImagePicker/QBSlomoIconView.m
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ - (void)drawRect:(CGRect)rect
{
[self.iconColor setStroke];

CGFloat width = 2.2;
CGFloat width = 2.2f;
CGRect insetRect = CGRectInset(rect, width / 2, width / 2);

// Draw dashed circle
UIBezierPath* circlePath = [UIBezierPath bezierPathWithOvalInRect:insetRect];
circlePath.lineWidth = width;
CGFloat ovalPattern[] = {0.75, 0.75};
CGFloat ovalPattern[] = {0.75f, 0.75f};
[circlePath setLineDash:ovalPattern count:2 phase:0];
[circlePath stroke];
}
Expand Down
2 changes: 1 addition & 1 deletion QBImagePicker/QBVideoIconView.m
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ - (void)drawRect:(CGRect)rect
[trianglePath fill];

// Draw rounded square
UIBezierPath *squarePath = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(CGRectGetMinX(self.bounds), CGRectGetMinY(self.bounds), CGRectGetWidth(self.bounds) - CGRectGetMidY(self.bounds) - 1.0, CGRectGetHeight(self.bounds)) cornerRadius:2.0];
UIBezierPath *squarePath = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(CGRectGetMinX(self.bounds), CGRectGetMinY(self.bounds), CGRectGetWidth(self.bounds) - CGRectGetMidY(self.bounds) - 1.0f, CGRectGetHeight(self.bounds)) cornerRadius:2.0f];
[squarePath fill];
}

Expand Down