views:

448

answers:

5

Hi there, i searched and tried a lot. But i really have no idea how to solve this – Thanks for your help

The Error-MSG:

Program received signal:  “EXC_BAD_ACCESS”.

The Line throwing the MSG

log(sos_Trace, @"sendMail");

Important

I make use of this logging-lib: http://code.google.com/p/soslog-objc/

Full SourceFile

#import "ContactViewController.h"
#import "SOSLog.h"

@implementation ContactViewController

@synthesize mailButton, delegate;

- (void)viewDidLoad {  
    self.view.backgroundColor = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"bg_tile.gif"]];  
    [super viewDidLoad];  
}  

- (IBAction)sendMail:(id)sender {
    NSLog(@"sendMail");
    log(sos_Trace, @"sendMail");

    [delegate mail:self];
}

- (void)dealloc {
    [self.mailButton release];
    self.delegate = nil;
    [super dealloc];
}

@end
+1  A: 

I've not used the soslog framework before, so I can't offer any insight there. However, EXC_BAD_ACCESS is frequently caused by trying to access an object that's either been dealloc'd, or never initialized to begin with. Has sos_Trace been set up before you call it?

Ben Gottlieb
I briefly checked out the library docs, it looks like sos_Trace is an enum.
benzado
+1  A: 

EXC_BAD_ACCESS means you are trying to access memory at an invalid address. It usually happens when you try to use a pointer that hasn't been initialized and is pointing to some random location in memory.

I don't know anything about that logging library, but I would guess is that there is some setup or initialization function that you need to call. Looking at the website it doesn't seem like there is, though.


One other thing that sticks out, though is probably not related, is the line

[self.mailButton release];

in your dealloc method. It's probably not a problem since it is in your dealloc method, but if you're going to use a property accessor you should leave the retain and release to it. If you had that line in any other place, you'd cause a EXC_BAD_ACCESS later if the mailButton property was reassigned. That's because:

self.mailButton = THING; // retain count +1
[self.mailButton release]; // retain count -1
self.mailButton = OTHER; // EXC_BAD_ACCESS!

That's because the third line is really a call to setMailButton:, which internally calls [THING release], but since you already released it, you have now unbalanced your retain/release calls and so either then or later (if somebody else has retained it) release will be called on an invalid object and your program goes kablooey.

benzado
+2  A: 

Having a look at the source for the SOS logging framework, log(sos_Trace, @"sendMail"); cannot possibly be the source of the crash unless you have code elsewhere that is corrupting the internals of the logging infrastructure.

Post the full stacktrace of the crash.

As @benzado noted, you have some bugs in your memory management code. Fix those, too. I would suggest running the static analyzer over your code and fixing anything it finds. shift-cmd-A in Xcode should do the trick.

Also, if you want to log when a method is called, this will work in any method:

log(sos_Trace, NSStringFromSelector(_cmd));

Or:

NSLog(@"[%@ %@] -- your message here", NSStringFromClass([self class]), NSStringFromSelector(_cmd));
bbum
A: 

Fixed the bug. The socket was dealloced due to a missing retain.

meinhard
A: 

Thanks meinhard. Now everything works fine.

fabian