Custom photo app crashes saving image.

Discussion in 'iOS Programming' started by snakebytes, Nov 16, 2009.

  1. snakebytes macrumors newbie

    Nov 16, 2009
    I've had a custom photo app built and am now trying to fix an error/bug. In 2.2 the app functions perfectly, but in 3.1 the application crashes when attempting to take a picture.

    In 2.2, when I hit the shutter release button, after a moment an image is saved to the photo library. In 3.1, when I hit the shutter release button the app closes.

    I hope someone can tell me if there's something obvious in the code..

    Thanks, Chris

    The following is the code (which xcode is showing as error)

    - (UIImage*)correctImageOrientation:(CGImageRef)imag e {
    CGImageRef img = UIGetScreenImage();
    UIImage* scImage=[UIImage imageWithCGImage:img];
    return scImage;
    //UIImage imageWithCGImage:UIGetScreenImage();
    - (BOOL)grabPictureFromImageView:(UIView*)view {
    CGImageRef img = (CGImageRef)[view imageRef];
    if (img)
    // Taken image is in UIImageOrientationRight orientation
    UIImage *photo = [self correctImageOrientation:img]; // get the captuered image in the photo with correct orientation
    //UIImageWriteToSavedPhotosAlbum(photo, nil, nil, nil);
    UIImageWriteToSavedPhotosAlbum(photo, self, @selector(imageSavedToPhotosAlbum:didFinishSavingW ithError:contextInfo:), nil); //save the image in the album
    [imageCopy release]; imageCopy = nil;
    return YES;
    return NO;
  2. kainjow Moderator emeritus


    Jun 15, 2000
    My guess is UIGetScreenImage() returns an image that you should not release. That is usually how Get functions work, so try removing the CFRelease(img); line.
  3. snakebytes thread starter macrumors newbie

    Nov 16, 2009
    I'll try it tonight. Thanks.

    Thanks for your advice Kainjow, I'll give it a shot!
  4. snakebytes thread starter macrumors newbie

    Nov 16, 2009
    Didn't work :(

    Hey, I tried that. It didn't work! any other suggestions?

  5. PhoneyDeveloper macrumors 68040


    Sep 2, 2008
    What line does it crash on? What kind of crash is it? What text is shown in the debugger console when it crashes?
  6. snakebytes thread starter macrumors newbie

    Nov 16, 2009

    I am not exactly sure what line it crashes on. I get a warning when compiling the code "Implicit declaration of function "UIGetScreenImage" as well as "Initialization makes pointer from integer without a cast" on the line " CGImageRef img= UIGetScreenImage();"

    And "UIView" mat no respond to "-imageRef" on the line "CGImageRef img = (CGImageRef)[view imageRef];"

    The crash when debugging is a SIGABRT signal sent. Basically, the application entirely quits.

    This is the crash log :

    Exception Type: EXC_CRASH (SIGABRT)
    Exception Codes: 0x00000000, 0x00000000
    Crashed Thread: 0

    Thread 0 Crashed:
    0 libSystem.B.dylib 0x31a279ac 0x319a9000 + 518572
    1 libSystem.B.dylib 0x31a2799c 0x319a9000 + 518556
    2 libSystem.B.dylib 0x31a2798e 0x319a9000 + 518542
    3 libSystem.B.dylib 0x31a3c63a 0x319a9000 + 603706
    4 libstdc++.6.dylib 0x3361d3b0 0x335d8000 + 283568
    5 libobjc.A.dylib 0x32401858 0x323fc000 + 22616
    6 libstdc++.6.dylib 0x3361b776 0x335d8000 + 276342
    7 libstdc++.6.dylib 0x3361b7ca 0x335d8000 + 276426
    8 libstdc++.6.dylib 0x3361b896 0x335d8000 + 276630
    9 libobjc.A.dylib 0x32400714 0x323fc000 + 18196
    10 CoreFoundation 0x32537b86 0x32511000 + 158598
    11 CoreFoundation 0x32537b24 0x32511000 + 158500
    12 Foundation 0x3140d8cc 0x313ed000 + 133324
    13 Foundation 0x31432ca8 0x313ed000 + 285864
    14 Turbo 0x00005ff0 -[RootViewController getCamShutButton] (RootViewController.m:162)
    Thread 0 crashed with ARM Thread State:
    r0: 0x00000000 r1: 0x00000000 r2: 0x00000001 r3: 0x383c43cc
    r4: 0x00000006 r5: 0x3361b30d r6: 0x001509dc r7: 0x2fffea00
    r8: 0x2fffe9ec r9: 0x00000065 r10: 0x00000001 r11: 0x001503b0
    ip: 0x00000025 sp: 0x2fffea00 lr: 0x31a279a3 pc: 0x31a279ac
    cpsr: 0x000f0010

    Thanks so much.!

  7. PhoneyDeveloper macrumors 68040


    Sep 2, 2008
    Couple things.

    This code makes me shudder.

    Those two lines that throw compiler errors are because those methods are either undocumented or non-existent. Apparently UIGetScreenImage() does exists but isn't documented. If you want to continue using it you should add this to the top of the source file.

    extern "C" CGImageRef UIGetScreenImage();
    It is possible that UIImageView has a private method called imageRef and it's possible that the view passed to your grabPictureFromImageView is really a UIImageView and not a UIView.

    I notice that the method from your code shown in the stack trace is getCamShutButton, which isn't one of the methods whose source you show.

    Unless you can step through the source code and into the getCamShutButton to figure out where and why it's crashing I'm not sure what help I can be.

    If the code you show is indicative of the quality of the rest of the code in your project this won't be the only bug. You probably need to find a real developer to look at the code and fix it.
  8. snakebytes thread starter macrumors newbie

    Nov 16, 2009
    Would you give me a quote?

    Would you be interested in taking a look at the code and giving me a quote? The thing is I've spent a whole lot already and am left with an app which doesn't function. I know it's probably better to go through and clean it all up, but I'd prefer if you'd just fix the problem and leave the mess. :)

    It does work flawlessly on 2.2, it's only in 3.1 that it crashes.

    you can email me at chris "at"

    Thanks so much,


Share This Page