Ios 在Xcode 6上的设备上调试EXC_错误访问
当我在iPhone上运行而不是在模拟器上运行时,我会犯这个可怕的错误。我曾尝试过为僵尸、分配和突然终止运行工具,但后者不会在设备上运行。这些工具没有突出显示任何异常。也许我用错了,但这似乎很直截了当 基本上,当我将第二组数据阵列添加到应用程序中时,我会遇到这个错误,在模拟器上,它使用大约70MB的数据,而没有第二组,它使用20到40MB的数据。看起来我只是因为iPhone 4s内存不足,但从我所读到的来看,这不太可能。从分配工具来看,最后发生的事情是VM分配,但我不知道它是否成功。这仪器一点也没说什么 有没有人有办法追踪Xcode 6的问题并在设备上运行?我的应用程序正在使用ARC。是否有我应该知道的调试器控制台命令 谢谢 PS:我也在Xcode中启用了僵尸对象,但也没有关于错误的线索 以下是我被要求发布的代码:Ios 在Xcode 6上的设备上调试EXC_错误访问,ios,objective-c,debugging,opengl,exc-bad-access,Ios,Objective C,Debugging,Opengl,Exc Bad Access,当我在iPhone上运行而不是在模拟器上运行时,我会犯这个可怕的错误。我曾尝试过为僵尸、分配和突然终止运行工具,但后者不会在设备上运行。这些工具没有突出显示任何异常。也许我用错了,但这似乎很直截了当 基本上,当我将第二组数据阵列添加到应用程序中时,我会遇到这个错误,在模拟器上,它使用大约70MB的数据,而没有第二组,它使用20到40MB的数据。看起来我只是因为iPhone 4s内存不足,但从我所读到的来看,这不太可能。从分配工具来看,最后发生的事情是VM分配,但我不知道它是否成功。这仪器一点也没
//***************************************************/
// 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];
选择“视图”菜单、“导航器”、“断点导航器”⌘七, 然后单击断点导航器列左下角的+并选择添加异常断点。控件单击或右键单击生成的断点,并将其更改为在所有Objective-C异常上中断 然后,作为最后一步,再次右键单击断点并选择将断点移动到>用户。这使断点成为所有项目的全局断点
一旦添加了异常断点,Xcode就更有可能在错误的源行中断。这并不完美,但它确实使您更有可能在main.m中看到实际的行,而不是一行,这是没有用的。您是否收到任何内存警告?在这些回拨中放置一个NSLog。你有可以共享的符号化崩溃日志吗?是的,我的内存中有NSLog警告回拨,但没有发出警告回拨。我似乎无法获取崩溃日志,因为iPhone没有显示在我的设备上。有没有办法让它脱离Xcode?这很有趣,因为它在一条线上中断了NSLog@Processing%lu个星座,未签名的longconstellations.count;但是,似乎是由于NSArray星座不再存在而导致访问失败。在变量窗口中,在曾经包含88个条目的星座中没有更多的对象,只有一个空数组——只有一个更像错误工件的对象——带有指针地址。那么,为什么这个阵列以及其他阵列似乎遭到了重创?我找不到的。如果我减小以前创建的阵列的大小,应用程序将顺利运行。顺便说一句,如果我删除发生故障的NSLog行,它只会在代码中再出现几行。哇!我只是在检查调试器中的变量时注意到了一些东西。我前面提到的第二个数据数组似乎没有创建顶点星座顶点[总顶点];-在单步执行该行代码之后,数组不会显示在“我的变量”窗口中,并且其设置为“显示全部”。怎么会这样呢?如果我再设置一两行断点。许多物体似乎被撞击了。因此,分配第二个数据数组似乎是问题的根源。但是如果相反,我一步一步地通过数组分配一直到NSLog行,对象看起来完好无损,但我仍然得到错误的访问错误。然后在创建数组的位置发布代码。我的猜测是,你宣布它是弱的,它正在被释放并设置为零。
#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];
}