views:

24

answers:

3

Hi all,

I have a modal view controller which is crashing when it dismisses itself. The error is EXC_BAD_ACCESS (yipee). I am tryin got use NSZombie to work out the problem. I get am getting the following :

2010-10-20 17:15:58.936 [24058:207] AddRunningClient starting device on non-zero client count 2010-10-20 17:16:06.846 [24058:207] * -[ViewController retain]: message sent to deallocated instance 0x6c2d4a0

What does this mean - does it mean that a message was sent to the Viewcontroller or that a message was sent to an object in the Viewcontroller ?

I am really stuck as the thread seems to be main :(

Thanks all in advance for any help,

Martin

EDIT

Thanks all for the quick replies. Here is how I am presenting the view controller :

-(IBAction)letsstartGame {

ViewController * sl = [[ViewController alloc] initWithNibName:@"ViewController" bundle:[NSBundle mainBundle]];  
self.viewLink = sl;
[sl release];

[mainMenu stop];
[mainMenu setCurrentTime:0.0];

[self presentModalViewController:viewLink animated:NO];

[viewLink release];
self.viewLink = nil;

}

And dismiss like this :

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {

if (waitingOver) {

    [backgroundMain stop];
    [fireworks stop];

    [self dismissModalViewControllerAnimated:NO];

}   

}

+1  A: 

It means you are sending a message to a deallocated instance. So somewhere in your code you have failed to retain an object (probably ViewController) or have released it prematurely.

If you can post your code where you create the View Controller that might be helpful for us to debug.

fsmc
Thanks - I've put my code above.
Ohnomycoco
+1  A: 

That means that you had an instance of an object of type ViewController, it was deallocated, and then you tried to retain it.

edit

You're over-releasing the object. Here's what you're doing:

ViewController * sl = [[ViewController alloc] initWithNibName:@"ViewController" bundle:[NSBundle mainBundle]];  //allocated, has a +1 retain count
self.viewLink = sl;  //assuming a retain property, has a +2 retain count
[sl release]; //releasing, now has +1 retain count
....    
[viewLink release]; //releasing, now has a 0 retain count
self.viewLink = nil; //attempting to release stale pointer, will result in a crash (perhaps not immediately, but eventually)

Get rid of the [viewLink release] line. It is wrong to have that in there.

Dave DeLong
Thanks Dave. However if I remove that line the viewcontroller is not destroyed when it dismisses itself - viewcontroller is still there when I reinstantiate it.
Ohnomycoco
And dealloc is not called in the viewcontroller
Ohnomycoco
@Ohnomycoco yeah, because technically the `presentModalViewController` method is also retaining the view controller. The point of the comments above was to show that your memory management is imbalanced.
Dave DeLong
right but when the modal view controller dismisses itself should it not be destroyed ?
Ohnomycoco
Oh God I'm such an idiot....I had set the game to start at gameover so I could test....LOL
Ohnomycoco
+1  A: 

The message is basically saying that you are trying to send a message (call a function) on/to an object that has already been dealloc'd (released and the memory freed). If you could send more code, I could perhaps attempt to determine why.

ACBurk
Thanks - I've put the code above.
Ohnomycoco