簡體   English   中英

在Xcode 6的設備上調試EXC_BAD_ACCESS

[英]Debug EXC_BAD_ACCESS on device on Xcode 6

當我在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];
}

選擇視圖菜單,導航器,斷點導航器(⌘7)。

然后單擊斷點導航器列左下方的+,然后選擇“添加異常斷點”。 按住Control鍵單擊(或右鍵單擊)結果斷點,然后將其更改為在所有Objective-C異常時都中斷。

然后,作為最后一步,再次右鍵單擊該斷點,然后選擇“將斷點移至>用戶”。 這使所有項目的斷點變為全局。

添加異常斷點后,Xcode更有可能在錯誤的源代碼行上中斷。 這不是完美的方法,但是它確實使您更有可能看到實際的行,而不是main.m中的行,這沒有用。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM