在Xcode 6上的设备上调试EXC_BAD_ACCESS

时间:2015-03-08 18:08:43

标签: ios objective-c debugging opengl exc-bad-access

当我在iPhone上运行而不是在模拟器上运行时,我遇到了这个可怕的错误。我已经尝试过运行僵尸,分配和突然终止的仪器,但后者不会在设备上运行。这些工具没有突出任何与众不同的东西。也许我错误地使用它们,但它似乎非常直接。

基本上,当我向应用程序添加第二组数据阵列时,我收到此错误,在模拟器上它使用大约70MB而没有第二组则使用20到40MB。看起来我只是内存不足(iPhone 4s),但从我读过的内容来看,这不太可能。从分配工具中,最后发生的事情是VM分配,但我不知道它是否成功或任何事情。该仪器根本没有说什么。

有没有人有办法用Xcode 6跟踪这个问题并在设备上运行? (我的应用程序正在使用ARC。)是否有我应该知道的调试器控制台命令?

由于

PS:我还在Xcode中启用了僵尸对象,但也没有关于错误的线索。

以下是我要求发布的代码:

//***************************************************/
// Process the constellation lines catalog for OpenGL
//***************************************************/

// Must create a set of polygon objects to be drawn separately
// Each with a vertex and index buffer

NSMutableString *constellationName = [[NSMutableString alloc] init];
NSMutableArray *constellationsTemp = [[NSMutableArray alloc] init];

// Do a points and lines scatter plot of the catalog data
int totalVertices = 0;
for (i=0; i<constellationLinesCatalogData.count;) {
    constellationName = [[constellationLinesCatalogData objectAtIndex:i] objectAtIndex:CON_INDEX];
    NSMutableArray *constellation = [[NSMutableArray alloc] init];
    while ((i<constellationLinesCatalogData.count) && [[[constellationLinesCatalogData objectAtIndex:i] objectAtIndex:CON_INDEX] isEqualToString:constellationName]) {
        NSMutableArray *constellationVerticesArray = [[NSMutableArray alloc] init];
        NSMutableArray *constellationIndicesArray = [[NSMutableArray alloc] init];
        while (![[[constellationLinesCatalogData objectAtIndex:i] objectAtIndex:STAR_INDEX] isEqualToString:@""]) {
            cos_ra = cosf(GLKMathDegreesToRadians(
                                                  15*(
                                                      [[[constellationLinesCatalogData objectAtIndex:i] objectAtIndex:RA_INDEX] floatValue]
                                                      )
                                                  ));
            sin_ra = sinf(GLKMathDegreesToRadians(
                                                  15*(
                                                      [[[constellationLinesCatalogData objectAtIndex:i] objectAtIndex:RA_INDEX] floatValue]
                                                      )
                                                  ));
            cos_dec = cosf(GLKMathDegreesToRadians(
                                                   [[[constellationLinesCatalogData objectAtIndex:i] objectAtIndex:DE_INDEX] floatValue]
                                                   ));
            sin_dec = sinf(GLKMathDegreesToRadians(
                                                   [[[constellationLinesCatalogData objectAtIndex:i] objectAtIndex:DE_INDEX] floatValue]
                                                   ));

            NSArray *Position = [[NSArray alloc] initWithObjects:
                                 [NSNumber numberWithFloat:cos_dec*cos_ra],  // X
                                 [NSNumber numberWithFloat:cos_dec*sin_ra],  // Y
                                 [NSNumber numberWithFloat:sin_dec],         // Z
                                 [NSNumber numberWithFloat:1.0],
                                 nil];

            NSArray *Color = [[NSArray alloc] initWithObjects:
                              [NSNumber numberWithFloat:0.5],
                              [NSNumber numberWithFloat:0.5],
                              [NSNumber numberWithFloat:0.5],
                              [NSNumber numberWithFloat:1.0],
                              nil];

            NSArray *TexCoord0 = [[NSArray alloc] initWithObjects:
                                  [NSNumber numberWithFloat:1.0],
                                  [NSNumber numberWithFloat:1.0],
                                  nil];

            NSArray *TexCoord1 = [[NSArray alloc] initWithObjects:
                                  [NSNumber numberWithFloat:1.0],
                                  [NSNumber numberWithFloat:1.0],
                                  nil];

            NSArray *Pointsize = [[NSArray alloc] initWithObjects:
                                  [NSNumber numberWithFloat:DEFAULT_POINT_SIZE],
                                  nil];

            NSArray *constellationVertex = [[NSArray alloc] initWithObjects:
                                            Position,
                                            Color,
                                            TexCoord0,
                                            TexCoord1,
                                            Pointsize,
                                            nil];

            [constellationVerticesArray addObject:constellationVertex];
            [constellationIndicesArray addObject:[[NSNumber alloc] initWithUnsignedInteger:totalVertices]];

            totalVertices++;
            i++;
        }
        NSArray *figure = [[NSArray alloc] initWithObjects:
                           [[constellationLinesCatalogData objectAtIndex:i] objectAtIndex:CON_INDEX],
                           constellationVerticesArray,
                           constellationIndicesArray,
                           nil];

        [constellation addObject:figure];

        i++;
    }
    [constellationsTemp addObject:constellation];
}
NSArray *constellations = [[NSArray alloc] initWithArray:constellationsTemp copyItems:YES];

NSLog(@"constellations.count = %lu", (unsigned long)constellations.count);
NSLog(@"totalVertices = %d", totalVertices);

// Setup constellation buffers
Vertex constellationVertices[totalVertices];
GLuint constellationIndices[totalVertices*2];

嗯,这个问题一直存在。除了EXC_BAD_ACCESS代码1之外,没有任何信息可以跟踪它。堆栈跟踪只是将设置方法显示为最后一次调用。我认为这个问题出现在我的视图控制器中,但经过大量的反复试验后,它认为它必须是它的方式,但也许有一个我无法看到的微妙问题。这是我的视图控制器代码,它调用立即崩溃的安装方法 - 您可能只需要查看最后的OpenGL设置:

#import "GBStarFieldViewController.h"
#import "GBStarFieldView.h"

#define MOTION_UPDATE_INTERVAL (1/30) // seconds

@interface GBStarFieldViewController ()

@end

@implementation GBStarFieldViewController {

    int i;
    CLLocationManager *locationManager;
    CMMotionManager *motionManager;
    GBStarFieldView *starFieldView;

}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    NSLog(@"GBStarFieldViewController viewDidLoad invoked");

    /****************************/
    // Register for notifications
    /****************************/

    NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
    [center addObserver:self
               selector:@selector(tapDetected:)
                   name:@"TapDetected"
                 object:nil];

    [center addObserver:self
               selector:@selector(pinchDetected:)
                   name:@"PinchDetected"
                 object:nil];

    [center addObserver:self
               selector:@selector(oneTouchPanDetected:)
                   name:@"OneTouchPanDetected"
                 object:nil];

    [center addObserver:self
               selector:@selector(twoTouchPanDetected:)
                   name:@"TwoTouchPanDetected"
                 object:nil];

    /****************************************************/
    // Setup location manager
    /****************************************************/

    if ([CLLocationManager locationServicesEnabled] && [CLLocationManager headingAvailable]) {
        locationManager = [[CLLocationManager alloc] init];
        locationManager.delegate = self;
        locationManager.headingFilter = kCLHeadingFilterNone;
        locationManager.distanceFilter = kCLHeadingFilterNone;
        locationManager.desiredAccuracy = kCLLocationAccuracyBest;
        [locationManager startUpdatingLocation];
        [locationManager startUpdatingHeading];
        if ([locationManager respondsToSelector:@selector(requestAlwaysAuthorization)]) {
            [locationManager requestAlwaysAuthorization];
        }
    } else {
        NSLog(@"Error: Failed to get heading services");
    }

    /****************************************************/
    // Setup motion manager
    /****************************************************/

    if ([CMMotionManager availableAttitudeReferenceFrames] & CMAttitudeReferenceFrameXTrueNorthZVertical) {
        motionManager = [[CMMotionManager alloc] init];
        [motionManager startDeviceMotionUpdatesUsingReferenceFrame:CMAttitudeReferenceFrameXTrueNorthZVertical];
        motionManager.deviceMotionUpdateInterval = MOTION_UPDATE_INTERVAL;
    } else {
        NSLog(@"Error: Failed to get reference frame");
    }

    /*******************/
    // Initialize OpenGL
    /*******************/

    // Create an OpenGL ES context and assign it to the view loaded from storyboard
    starFieldView = (GBStarFieldView *)self.view;
    starFieldView.context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2];

    [starFieldView setup];
}

1 个答案:

答案 0 :(得分:0)

选择视图菜单,导航器,断点导航器(⌘7)。

然后单击断点导航器列左下角的+并选择“添加异常断点”。按住Control键并单击(或右键单击)生成的断点,并将其更改为中断所有Objective-C异常。

然后作为最后一步,再次右键单击断点并选择Move Breakpoint to&gt; User。这使得所有项目的断点都是全局的。

一旦添加了异常断点,Xcode就更容易在错误的源代码行中断。这并不完美,但它确实使你更有可能看到实际的行而不是main.m中的一行,这是没用的。