iOS app crash only when not debugging

7

I am using testflight to test my app, and I have a crash that only occurs when the app is built for ad-hoc and distributed through test flight. The relevant crash report details are:

Date/Time:       2012-06-11 09:00:34.638 +0800
OS Version:      iPhone OS 5.1.1 (9B206)
Report Version:  104

Exception Type:  EXC_BAD_ACCESS (SIGSEGV)
Exception Codes: KERN_INVALID_ADDRESS at 0x00000009
Crashed Thread:  0

Thread 0 name:  Dispatch queue: com.apple.main-thread
Thread 0 Crashed:
0   libobjc.A.dylib                 0x34e74f78 objc_msgSend + 16
1   appName                         0x0002963e __24-[XYPieChart reloadData]_block_invoke_0168 (XYPieChart.m:321)
2   libdispatch.dylib               0x30295c52 _dispatch_call_block_and_release + 6
3   libdispatch.dylib               0x302a0e8a _dispatch_main_queue_callback_4CF$VARIANT$up + 190
4   CoreFoundation                  0x371482a6 __CFRunLoopRun + 1262
5   CoreFoundation                  0x370cb49e CFRunLoopRunSpecific + 294
6   CoreFoundation                  0x370cb366 CFRunLoopRunInMode + 98
7   GraphicsServices                0x3388a432 GSEventRunModal + 130
8   UIKit                           0x30e77cce UIApplicationMain + 1074
9   appName                         0x00003b20 main (main.m:14)
10  appName                         0x00003ad8 0x1000 + 10968

and the code that is referenced - (XYPieChart.m:321)

    [CATransaction begin];
    [CATransaction setAnimationDuration:_animationSpeed];

    [_pieView setUserInteractionEnabled:NO];

    __block NSMutableArray *layersToRemove = nil;
    [CATransaction setCompletionBlock:^{

        if (layersToRemove) {
            [layersToRemove enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
                if (obj)
                    [obj removeFromSuperlayer];
            }];

            [layersToRemove removeAllObjects];
        }

        for(SliceLayer *layer in _pieView.layer.sublayers)
        {
            [layer setZPosition:kDefaultSliceZOrder];
        }

        [_pieView setUserInteractionEnabled:YES];
    }];

    BOOL isOnStart = ([slicelayers count] == 0 && sliceCount);
    NSInteger diff = sliceCount - [slicelayers count];
    layersToRemove = [NSMutableArray arrayWithArray:slicelayers];

    BOOL isOnEnd = ([slicelayers count] && (sliceCount == 0 || sum <= 0));
    if(isOnEnd)
    {
        for(SliceLayer *layer in _pieView.layer.sublayers){
            [self updateLabelForLayer:layer value:0];
            [layer createArcAnimationForKey:@"startAngle"
                                  fromValue:[NSNumber numberWithDouble:_startPieAngle]
                                    toValue:[NSNumber numberWithDouble:_startPieAngle] 
                                   Delegate:self];
            [layer createArcAnimationForKey:@"endAngle" 
                                  fromValue:[NSNumber numberWithDouble:_startPieAngle]
                                    toValue:[NSNumber numberWithDouble:_startPieAngle] 
                                   Delegate:self];
        }
        [CATransaction commit];
        return;
    }

I would be able to track down the problem if I could reproduce it when debugging but it only seems to occur when built for ad-hoc. Thanks!

Edit: Using the simulator, I have tracked down the problem to a EXC_BAD_ACCESS at this line

[layersToRemove enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
objective-c
ios
crash
testflight
asked on Stack Overflow Jun 11, 2012 by danielbeard • edited Jun 12, 2012 by danielbeard

4 Answers

9

I had a similar problem and tried changing the project build settings, but it didn't work for me. Eventually solved my problem by changing the compiler optimization level setting for the release:

In Build Settings, go to the LLVM compiler 4.2 - Code Generation section, look for the Optimization Level option and change the Release setting from Fastest, Smallest [-Os] to None [-O0].

Hope this helps!

answered on Stack Overflow Feb 6, 2013 by user1145581
8

Change your Xcode Scheme so that you can Test and Debug a Release build, which uses the same compiler optimizations as your Ad Hoc build. Debugging a Debug build does not.

answered on Stack Overflow Jun 11, 2012 by hotpaw2
6

I ended up working out the problem. In my compiler settings, somehow, ARC wasn't enabled for Ad-Hoc builds resulting in weird behaviour. Before I worked this out, allocating the __block variable worked because in non-ARC environments, __block variables are not retained automatically.

Changed compiler settings so that all builds use ARC and everything was fixed.

answered on Stack Overflow Jun 11, 2012 by danielbeard
3

In my case it was the "Enable Zombie Objects" setting that prevented the crash in debug mode. Debuggin without this setting made the app also crash in the debugger making it easy to find the culprit.

So I would advice to disable all settings in the "diagnostics" menu and set the optimizations to -Os and make a final test before releasing. Or as hotpaw2 pointed out, build in release mode. But this did not work for me due to issues with the certificate settings.

answered on Stack Overflow Sep 30, 2015 by Torge

User contributions licensed under CC BY-SA 3.0