From 0e7faf950d8e263f868eb20a80b349dbaeda232e Mon Sep 17 00:00:00 2001 From: Dick Smith Date: Mon, 14 Jan 2019 12:07:17 -0500 Subject: [PATCH] fix: various crashes from crash reporter 1. fix from PR #180, but with missing `}`. `: `Fatal Exception: NSInternalInconsistencyException attempt to delete and reload the same index path` 2. fix for `Fatal Exception: NSInvalidArgumentException *** -[NSPlaceholderString initWithString:]: nil argument` 3. fix for `Fatal Exception: NSInternalInconsistencyException negative sizes are not supported in the flow layout` 4. added type safety by explicitly setting some double literals to floats for `Parameter type mismatch: Values of type 'double' may not fit into the receiver type 'CGFloat'` --- QBImagePicker/QBAlbumsViewController.m | 28 ++++++++++----------- QBImagePicker/QBAssetsViewController.m | 34 +++++++++++++++++--------- QBImagePicker/QBCheckmarkView.m | 16 ++++++------ QBImagePicker/QBSlomoIconView.m | 4 +-- QBImagePicker/QBVideoIconView.m | 2 +- 5 files changed, 48 insertions(+), 36 deletions(-) diff --git a/QBImagePicker/QBAlbumsViewController.m b/QBImagePicker/QBAlbumsViewController.m index a08dfe28..a5a352ba 100644 --- a/QBImagePicker/QBAlbumsViewController.m +++ b/QBImagePicker/QBAlbumsViewController.m @@ -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(); @@ -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]; diff --git a/QBImagePicker/QBAssetsViewController.m b/QBImagePicker/QBAssetsViewController.m index 98177684..960278f1 100644 --- a/QBImagePicker/QBAssetsViewController.m +++ b/QBImagePicker/QBAssetsViewController.m @@ -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]; @@ -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]; } @@ -521,8 +524,9 @@ - (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; @@ -530,8 +534,9 @@ - (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView { 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; @@ -539,8 +544,9 @@ - (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView { 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; } @@ -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); } diff --git a/QBImagePicker/QBCheckmarkView.m b/QBImagePicker/QBCheckmarkView.m index aa25ac8c..e143c954 100644 --- a/QBImagePicker/QBCheckmarkView.m +++ b/QBImagePicker/QBCheckmarkView.m @@ -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 @@ -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]; diff --git a/QBImagePicker/QBSlomoIconView.m b/QBImagePicker/QBSlomoIconView.m index ba6e8670..3850d153 100644 --- a/QBImagePicker/QBSlomoIconView.m +++ b/QBImagePicker/QBSlomoIconView.m @@ -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]; } diff --git a/QBImagePicker/QBVideoIconView.m b/QBImagePicker/QBVideoIconView.m index 89844952..79d524be 100644 --- a/QBImagePicker/QBVideoIconView.m +++ b/QBImagePicker/QBVideoIconView.m @@ -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]; }