Browse Source

thumbnail cache: fix another potential runtime exception

Felix Paul Kühne 10 years ago
parent
commit
86816a9583
1 changed files with 3 additions and 2 deletions
  1. 3 2
      Sources/VLCThumbnailsCache.m

+ 3 - 2
Sources/VLCThumbnailsCache.m

@@ -196,11 +196,12 @@ static NSCache *_thumbnailCacheMetadata;
     }
 
     UIGraphicsBeginImageContext(imageSize);
-    for (NSUInteger i = 0; i < fileNumber; i++) {
+    NSUInteger iter = files.count < fileNumber ? files.count : fileNumber;
+    for (NSUInteger i = 0; i < iter; i++) {
         MLFile *file =  [files objectAtIndex:i];
         clusterThumb = [VLCThumbnailsCache thumbnailForMediaFile:file];
         CGContextRef context = UIGraphicsGetCurrentContext();
-        CGFloat imagePartWidth = (imageSize.width / fileNumber);
+        CGFloat imagePartWidth = (imageSize.width / iter);
         //the rect in which the image should be drawn
         CGRect clippingRect = CGRectMake(imagePartWidth * i, 0, imagePartWidth, imageSize.height);
         CGContextSaveGState(context);