Question

I have this code in my app:

[[self assetsLibrary] assetForURL:info.media.url resultBlock:^(ALAsset *asset) {
    ALAssetRepresentation *rep = [asset defaultRepresentation];
    CGImageRef img = [rep fullScreenImage];
    photoLayer.contents =  img;
} failureBlock:^(NSError *error) {

}];

The code gets to the line where the img variable is populated and stops there and the app locks with no errors. The NSLog echos out a size, so I know the asset is there. I am at a loss as to how to troubleshoot this, it was working before, but has just stopped! Does anyone see anything here that is out of place?

Here is what the url looks like:

assets-library://asset/asset.JPG?id=36E68169-7BB4-48D7-B8E1-244234C9F1DA&ext=JPG

Stack Trace while it is frozen:

Thread 1, Queue : NSManagedObjectContext Queue
#0  0x37b1af38 in syscall_thread_switch ()
#1  0x331a5978 in OSSpinLockLock$VARIANT$wfe ()
#2  0x3318bcae in pthread_once ()
#3  0x348f66e2 in _internalCheckSupportsDCTDownScaling ()
#4  0x348f63fa in _initalizeService ()
#5  0x3318bcde in pthread_once ()
#6  0x348f63ba in jpegService ()
#7  0x3497009c in FigCreateCGImageFromJPEG ()
#8  0x356b5728 in PLCreateImageFromDataWithFormat ()
#9  0x35a3205e in __block_global_0 ()
#10 0x356a03f4 in -[PLAssetsSaver requestSynchronousImageFromAsset:withFormat:completionBlock:] ()
#11 0x35a32028 in __40-[ALAssetRepresentation fullScreenImage]_block_invoke_0 ()
#12 0x35a387ec in __53-[ALAssetRepresentationPrivate _performBlockAndWait:]_block_invoke_0 ()
#13 0x328e79a0 in developerSubmittedBlockToNSManagedObjectContextPerform ()
#14 0x3121c5da in _dispatch_client_callout ()
#15 0x3121f80e in _dispatch_barrier_sync_f_invoke ()
#16 0x328e7b22 in -[NSManagedObjectContext performBlockAndWait:] ()
#17 0x35a351b2 in -[ALAssetsLibrary _performBlockAndWait:] ()
#18 0x35a385ac in -[ALAssetRepresentationPrivate _performBlockAndWait:] ()
#19 0x35a31f24 in -[ALAssetRepresentation fullScreenImage] ()
#20 0x0008a3ca in __31-[MasterTimeLine getPhotoItem:]_block_invoke_0 at /Users/jasoncandelora/Desktop/Glance/iOS/projects/VideoBuilderTest1/VideoBuilderTest1/MasterTimeLine.m:789
#21 0x35a371b2 in __block_global_14 ()
#22 0x3121c792 in _dispatch_call_block_and_release ()
#23 0x3121c5da in _dispatch_client_callout ()
#24 0x3121fe44 in _dispatch_main_queue_callback_4CF ()
#25 0x357ff1b0 in __CFRunLoopRun ()
#26 0x3577223c in CFRunLoopRunSpecific ()
#27 0x357720c8 in CFRunLoopRunInMode ()
#28 0x3702133a in GSEventRunModal ()
#29 0x340ec290 in UIApplicationMain ()
#30 0x0006eda4 in main at /Users/jasoncandelora/Desktop/Glance/iOS/projects/VideoBuilderTest1/VideoBuilderTest1/main.m:16


Thread 3, Queue : com.apple.libdispatch-manager
#0  0x37b1b5d0 in kevent64 ()
#1  0x31221d26 in _dispatch_mgr_invoke ()
#2  0x3121d378 in _dispatch_mgr_thread ()



Thread 5 WebThread, Queue : (null)
#0  0x37b1ae30 in mach_msg_trap ()
#1  0x37b1afd4 in mach_msg ()
#2  0x358002ba in __CFRunLoopServiceMachPort ()
#3  0x357ff030 in __CFRunLoopRun ()
#4  0x3577223c in CFRunLoopRunSpecific ()
#5  0x357720c8 in CFRunLoopRunInMode ()
#6  0x3376ea5c in RunWebThread(void*) ()
#7  0x331950e0 in _pthread_start ()
#8  0x33194fa8 in thread_start ()


Thread 8 com.apple.coremedia.player.async, Queue : (null)
#0  0x37b2b08c in __psynch_cvwait ()
#1  0x3318db00 in _pthread_cond_wait ()
#2  0x33197cfc in pthread_cond_wait ()
#3  0x336ef8b8 in FigSemaphoreWaitRelative ()
#4  0x39b30eae in fpa_AsyncMovieControlThread ()
#5  0x3370d97a in figThreadMain ()
#6  0x331950e0 in _pthread_start ()
#7  0x33194fa8 in thread_start ()





Thread 9 com.apple.coremedia.player.remote, Queue : (null)
#0  0x37b1ae30 in mach_msg_trap ()
#1  0x37b1afd4 in mach_msg ()
#2  0x39b370d8 in FigExpressNotificationThread ()
#3  0x3370d97a in figThreadMain ()
#4  0x331950e0 in _pthread_start ()
#5  0x33194fa8 in thread_start ()
Was it helpful?

Solution 3

In my case, I rebooted the device and it is working now. Thanks for all your help

OTHER TIPS

Try moving your final line of code to the main queue:

[[self assetsLibrary] assetForURL:info.media.url resultBlock:^(ALAsset *asset) {
    ALAssetRepresentation *rep = [asset defaultRepresentation];
    CGImageRef img = [rep fullScreenImage];
    dispatch_async(dispatch_get_main_queue(), ^{
        photoLayer.contents =  img;
    };
} failureBlock:^(NSError *error) {

}];

If that doesn't work, how large of an asset is this?

You shouldn't be using this sort of trickery trying to force the asynchronous asset retrieval operations into a synchronous operation. Most likely the reason for this is a deadlock, inspect the stack traces for the various threads and you probably see multiple threads waiting on a semaphore.

I suggest you remove the semaphore locking stuff and let the operation be asynchronous.

Another suggestion: have you made sure that the user actually has permitted access to the photos (new privacy setting on iOS6)?

Regarding the stack output you posted:

I see a FigSemaphoreWaitRelative and OSSpinLockLock$VARIANT$wfe. The first being waiting for a semaphore to be unlocked. The latter being another form of lock while the system apparently checks if the media you are trying to access can be decoded in hardware (_internalCheckSupportsDCTDownScaling).

For some reason this operation not only gets stuck, but it also blocks the main thread which is thread 1. Do you maybe have a media player view open (com.apple.coremedia.player.async) which is blocking the video hardware and this prevents the above DCTDownScaling check to deadlock?

Long story short: sounds like you should file a Radar for this, very much looks like an iOS bug to me.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top