0
votes

I'm getting EXC_BAD_ACCESS in random locations. Already tried to use NSZombieEnabled=YES but nothing different happens. I'm using xcode 4. Already tried: Enable Scribble, Enable Guard Edges, Enable Guard Malloc (only works at the simulator, very slow!), Memory Logging, and etc... No luck.

Anyone can suggest me another way to try to find the defect? I'm running out of options.

Thanks in Advance,

  • New information

Inside: (void)applicationDidFinishLaunching:(UIApplication *)application

I create a Timer: ASMInterrupt = [NSTimer scheduledTimerWithTimeInterval:1/60.0 target:self selector:@selector(interrupiSSao:) userInfo:nil repeats:YES];

And a new thread: [NSThread detachNewThreadSelector: @selector(myBackgroundMethod: ) toTarget:self withObject:nil];

Timer will be in a loop until myBackgroundMethod is running.

Inside myBackgroundMethod I use:

    //Beginning of the function
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
EAGLContext *context = [[EAGLContext alloc] initWithAPI: kEAGLRenderingAPIOpenGLES1 sharegroup: [[glView context] sharegroup]];
[EAGLContext setCurrentContext:context];

... //Several texture/sounds/music load, like this:

NSBundle *bundle = [NSBundle mainBundle];
sndMove = [[SoundFx alloc] initWithSound:[bundle pathForResource:@"tetMov" ofType:@"wav"]];

    txParallax[0] = [[Texture2D alloc] initWithImageFile:@"parallax_tst" ofType : @"png" inMode:TEX_RGBA];

NSString *tmpSom = [[NSBundle mainBundle] pathForResource:@"ThorTitle" ofType:@"mp3"]; musMenu = [[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:tmpSom] error:NULL]retain];

...

  //and at the end:
[EAGLContext setCurrentContext:nil];
[context release];
[pool release];

This only occur at the beginning of the app. And error always occurs after: 1) Long time playing 2) After game over and new game 3) At game over sequence

So, it might not be directly related to that thread. I tried to look for autorelease problems, but everything is allocated with initWith

3

3 Answers

1
votes

Try the static analyser (Cmd-Shift-B in Xcode 4, Cmd-Shift-A in Xcode 3). If you've got an over-released object or a double free, it will report it.

0
votes

Give the Memory Allocations instrument in Instruments a go. When you crash, you should be able to see historical allocation and free events at that address, including objective-c reference counting events.

0
votes

Apparently I was accessing an array out of it's boundaries:

int xpto[10][10];

xpto[10][5]=2; ... if (xpto[-1][8]!=...

How hard it would be for the debugger to give me some better information about it. That's why I can't wait to get my hands on a Nokia WinMo 7 phone. Visual Studio!!!