vpdn/MMLayershots

Layershots crashes on complex views

vpdn opened this issue · 2 comments

vpdn commented

This is possibly due to a memory issue. From the docs of NSAllocateMemoryPages:

Allocates the integral number of pages whose total size is closest to, but not less than, byteCount. The allocated pages are guaranteed to be filled with zeros. If the allocation fails, raises NSInvalidArgumentException.

Stacktrace:

2014-05-28 17:13:29.535 Clockshots[66470:6f1f] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** NSAllocateMemoryPages(2908160) failed'
*** First throw call stack:
(
    0   CoreFoundation                      0x02f831e4 __exceptionPreprocess + 180
    1   libobjc.A.dylib                     0x02d028e5 objc_exception_throw + 44
    2   CoreFoundation                      0x02f82fbb +[NSException raise:format:] + 139
    3   Foundation                          0x029dae1b NSAllocateMemoryPages + 106
    4   Foundation                          0x029a70d3 _NSDataCreateVMDispatchData + 37
    5   Foundation                          0x029a701e -[_NSPlaceholderData initWithBytes:length:copy:deallocator:] + 144
    6   Foundation                          0x029a7c9a -[NSData(NSData) initWithBytes:length:copy:freeWhenDone:bytesAreVM:] + 92
    7   Foundation                          0x0291f6d9 -[NSData(NSData) initWithBytes:length:] + 71
    8   Foundation                          0x029294cf +[NSData(NSData) dataWithBytes:length:] + 74
    9   Clockshots                          0x00159450 CGImageGetData + 592
    10  Clockshots                          0x00158b62 -[PSDWriter addLayerWithCGImage:andName:andOpacity:andOffset:] + 898
    11  Clockshots                          0x00156267 -[MMLayershots layershotForScreen:] + 2071
    12  Clockshots                          0x00155552 __46-[MMLayershots createLayershotAndCallDelegate]_block_invoke_2 + 98
    13  libdispatch.dylib                   0x032827b8 _dispatch_call_block_and_release + 15
    14  libdispatch.dylib                   0x032974d0 _dispatch_client_callout + 14
    15  libdispatch.dylib                   0x03285eb7 _dispatch_root_queue_drain + 291
    16  libdispatch.dylib                   0x03286127 _dispatch_worker_thread2 + 39
    17  libsystem_pthread.dylib             0x035c6dab _pthread_wqthread + 336
    18  libsystem_pthread.dylib             0x035cacce start_wqthread + 30
)
libc++abi.dylib: terminating with uncaught exception of type NSException
vpdn commented

This problem should be alleviated once #1 is implemented. Also instead of recursively going through the layers and building up a large set of images, which are then eventually saved to disk in a last step, we could save them right away after they're generated (e.g. through a block callback).

vpdn commented

Fixed with 5a7fa5f.