[英]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.