cvCvtColor CFDataGetBytes Crash on iOS

asked 2017-04-19 17:54:25 -0500

3DTOPO gravatar image

updated 2017-04-20 00:20:07 -0500

berak gravatar image

Hello,

I have used the same code successfully with thousands of images, but I got what seems like a freak crash report. I don't know if the issue is reproducible because I have only received a crash report from a user for it.

Any insight why this has worked for thousands of different images, but crashed on one would be greatly appreciated.

This is my method that crashed:

- (IplImage *)CreateGrayIplImageFromUIImage:(UIImage *)image {
    CGImageRef imageRef = image.CGImage;

    CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
    IplImage *iplimage = cvCreateImage(cvSize(image.size.width, image.size.height), IPL_DEPTH_8U, 4);
    CGContextRef contextRef = CGBitmapContextCreate(iplimage->imageData, iplimage->width, iplimage->height, iplimage->depth, iplimage->widthStep, colorSpace, kCGImageAlphaPremultipliedLast|kCGBitmapByteOrderDefault);

    CGContextDrawImage(contextRef, CGRectMake(0, 0, image.size.width, image.size.height), imageRef);
    CGContextRelease(contextRef);
    CGColorSpaceRelease(colorSpace);

    IplImage *ret = cvCreateImage(cvGetSize(iplimage), IPL_DEPTH_8U, 1);
    cvCvtColor(iplimage, ret, CV_RGBA2GRAY);
    cvReleaseImage(&iplimage);

    return ret;
}

The backtrace originates from cvCvtColor. This is a backtrace of the relevant threads:

Thread #10. Crashed: com.apple.root.default-qos
0  libsystem_platform.dylib       0x185fd8dd0 _platform_memmove + 112
1  CoreFoundation                 0x186e2679c CFDataGetBytes + 372
2  CoreFoundation                 0x186e2679c CFDataGetBytes + 372
3  ImageIO                        0x188d35c60 IIOImageRead::getCFDataBytesAtOffset(void*, unsigned long, unsigned long) + 216
4  ImageIO                        0x188d357b4 IIOImageRead::getBytesAtOffset(void*, unsigned long, unsigned long) + 348
5  ImageIO                        0x188bc893c read_fn2(png_struct_def*, unsigned char*, unsigned long) + 116
6  ImageIO                        0x188d66fc0 png_crc_read + 48
7  ImageIO                        0x188d6b178 png_read_IDAT_data + 308
8  ImageIO                        0x188db46a0 _cg_png_read_row + 188
9  ImageIO                        0x188bc87ac     ___ZN13PNGReadPlugin17copyImageBlockSetEP7InfoRecP15CGImageProvider6CGRect6CGSizePK14__CFDictionary_block_invoke + 560
10 libdispatch.dylib              0x185dd6e44 _dispatch_client_callout2 + 16
11 libdispatch.dylib              0x185de9e38 _dispatch_apply_invoke + 164
12 libdispatch.dylib              0x185dd69a0 _dispatch_client_callout + 16
13 libdispatch.dylib              0x185de6bac _dispatch_root_queue_drain + 888
14 libdispatch.dylib              0x185de67d0 _dispatch_worker_thread3 + 124
15 libsystem_pthread.dylib        0x185fdf1d0 _pthread_wqthread + 1096
16 libsystem_pthread.dylib        0x185fded7c start_wqthread + 4

Thread #5. com.apple.root.default-qos
0  TDTPhotoLib                    0x1008ce1d8 cvCvtColor + 61902
1  TDTPhotoLib                    0x10064f588 -[UIImage(OpenCV) equalArea] (UIImage+OpenCV.mm:52)
2  MyApp                         0x10015c098 TDTImageViewController.prepImage() -> () (TDTOptionsViewController.swift:783)
3  TDTPhotoLib                    0x1006a997c TDTCropImageViewController.(renderAspectImage() -> ()).(closure #1) (TDTCropImageViewController.swift:455)
4  libdispatch.dylib              0x185dd69e0 _dispatch_call_block_and_release + 24
5  libdispatch.dylib              0x185dd69a0 _dispatch_client_callout + 16
6  libdispatch.dylib              0x185de50d4 _dispatch_queue_override_invoke + 644
7  libdispatch.dylib              0x185de6a50 _dispatch_root_queue_drain + 540
8  libdispatch.dylib              0x185de67d0 _dispatch_worker_thread3 + 124
9  libsystem_pthread.dylib        0x185fdf1d0 _pthread_wqthread + 1096
10 libsystem_pthread.dylib        0x185fded7c start_wqthread + 4


Thread #8. com.apple.root.default-qos
0  libsystem_kernel.dylib         0x185f18e64 __psynch_mutexwait + 8
1  libsystem_pthread.dylib        0x185fe4c5c _pthread_mutex_lock_wait + 96
2  ImageIO                        0x188d35698 IIOImageRead::getBytesAtOffset(void*, unsigned long, unsigned long) + 64
3  ImageIO                        0x188bc893c read_fn2(png_struct_def*, unsigned char*, unsigned long) + 116
4  ImageIO                        0x188d670f4 png_crc_error + 56
5  ImageIO                        0x188d67048 png_crc_finish + 92
6  ImageIO                        0x188d6b0d4 png_read_IDAT_data + 144
7  ImageIO                        0x188db46a0 _cg_png_read_row + 188
8  ImageIO                        0x188bc87ac ___ZN13PNGReadPlugin17copyImageBlockSetEP7InfoRecP15CGImageProvider6CGRect6CGSizePK14__CFDictionary_block_invoke + 560
9  libdispatch.dylib              0x185dd6e44 _dispatch_client_callout2 + 16
10 libdispatch.dylib              0x185deaa3c _dispatch_apply_invoke_and_wait + 164
11 libdispatch.dylib              0x185dea47c dispatch_apply_f + 828
12 ImageIO                        0x188bc82b4 PNGReadPlugin::copyImageBlockSet(InfoRec*, CGImageProvider*, CGRect, CGSize, __CFDictionary const*) + 3472
13 ImageIO                        0x188bc5c50 PNGReadPlugin::CopyImageBlockSetProc(void*, CGImageProvider*, CGRect, CGSize, __CFDictionary const*) + 192
14 ImageIO                        0x188bcfbbc IIOImageProviderInfo::copyImageBlockSetWithOptions(CGImageProvider*, CGRect, CGSize, __CFDictionary const*) + 632
15 ImageIO                        0x188bcda14 IIOImageProviderInfo::CopyImageBlockSetWithOptions(void*, CGImageProvider*, CGRect, CGSize, __CFDictionary const*) + 340
16 CoreGraphics                   0x1884efef4 img_blocks_create + 264
17 CoreGraphics                   0x1884f7860 img_data_lock + 1872
18 CoreGraphics                   0x1884f70b8 CGSImageDataLock + 176
19 CoreGraphics                   0x1883171c0 ripc_AcquireImage + 756
20 ...
(more)
edit retag flag offensive close merge delete