Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS app crash only when not debugging

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) {
like image 707
danielbeard Avatar asked Jun 11 '12 02:06

danielbeard


People also ask

Why does my app keep crashing iOS?

When your apps keep crashing on your iPhone, updating them may just be the trick to solving it. To quickly check whether a specific app has an update, go to the App Store's Search tab to find the app. If an update is available, you'll see an Update button instead of the usual Open button. Tap on it to update the app.

Why does my app keep crashing when I try to open it?

If your Android apps keep crashing or freezing it's usually because you're low on space or running too many apps at once. Other reasons for crashing apps include a spotty Wi-Fi connection or an old version of the app that hasn't been updated.

What factors can cause an app to crash?

An Android app crashes whenever there's an unexpected exit caused by an unhandled exception or signal. An app that is written using Java or Kotlin crashes if it throws an unhandled exception, represented by the Throwable class.


3 Answers

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!

like image 152
user1145581 Avatar answered Sep 21 '22 16:09

user1145581


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.

like image 32
hotpaw2 Avatar answered Sep 21 '22 16:09

hotpaw2


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.

like image 34
danielbeard Avatar answered Sep 24 '22 16:09

danielbeard