2

I am currently using some pretty standard code to enumerate assets in a group. Except now I have a new error

*** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[NSOrderedSet enumerateObjectsAtIndexes:options:usingBlock:]: index 46 beyond bounds [0 .. 45]'

Here is the code that I am using.

 [group enumerateAssetsWithOptions:NSEnumerationReverse usingBlock:^(ALAsset *result, NSUInteger index, BOOL *stop) {
            NSLog(@"Asset %@", result);
            if (result != nil)
            {
                Asset *asset = [provider newAsset];
                asset.date = [result valueForProperty:ALAssetPropertyDate];
                id duration = [result valueForProperty:ALAssetPropertyDuration];
                asset.duration =  [NSDecimalNumber decimalNumberWithString:[NSString stringWithFormat:@"%@", duration]];
                CLLocation *location = [result valueForProperty:ALAssetPropertyLocation];
                asset.location = [location description];
                asset.orientation = [result valueForProperty:ALAssetPropertyOrientation];
                asset.type = [result valueForProperty:ALAssetPropertyType];
                NSDictionary *urls = [result valueForProperty:ALAssetPropertyURLs];
                for (NSString * key in urls) {
                    NSLog(@"Url = %@",[urls objectForKey:key]);
                    asset.url = [NSString stringWithFormat:@"%@", [urls objectForKey:key]];
                }

                [assetGroup addAssetsObject:asset];

                [asset release]; // Corrected based on comments

            }
        }];

The provider object is my custom database provider. But eliminating this code does no good. the top NSLog never gets fired which tells me that the enumeration code is having a problem outside my control. Has anyone else experienced this ?

The Lazy Coder
  • 11,560
  • 4
  • 51
  • 69
  • why are you calling `[asset autorelease]` instead of `[asset release]` (since it's being retained by the `assetGroup` array)? That seems like a potential crasher to me. – Michael Dautermann Nov 28 '11 at 19:19
  • the ALAsset is named result. the asset object is created by my provider using newAsset. and with normal convention I have been given a retain count using a method that starts with new. This object is in my Database. Sorry for the confusion. – The Lazy Coder Nov 28 '11 at 19:27
  • @MichaelDautermann: it is never incorrect to call `-autorelease` instead of `-release` – user102008 Feb 27 '13 at 21:52
  • It is not "Incorrect" to call autorelease. But it is a better option to simply release an object that you created and have finished with. I have updated the code to release the object that was created. – The Lazy Coder Feb 28 '13 at 21:08

3 Answers3

0

I'm seeing the same issue. It's a bug on Apple's side.

They execute the enumeration block in a separate thread and crash going out of bounds. What a shame! I cannot find a way to even catch this. App crashes, and there is nothing you can do until their library fixes itself.

Modifying the Camera Roll or sometimes launching iPhoto for iPad fixes the problem, but it will come back. Fortunately, it does not happen too often, but Apple has to react to this.

The iOSDev
  • 5,237
  • 7
  • 41
  • 78
Oleg
  • 1
0

This bug can be circumvented by setting the filters to photos, then videos, and enumerating for each one in turn, instead of keeping it at the default 'assets'.

I posted details here: ALAssetsLibrary seems to return wrong number of my photos

Community
  • 1
  • 1
Kalle
  • 13,186
  • 7
  • 61
  • 76
-1

Something was apparently messed up with my photo library. After clearing out my photos and running the application again, I am no longer getting this issue.

Sure wish I knew what the actual problem was and why the AssetsLibrary tried enumerating past the Bounds.

The Lazy Coder
  • 11,560
  • 4
  • 51
  • 69