Why does my cocoa program get EXC_BAD_ACCESS at startup?

When my cocoa application loads, my program crashes using messsage EXC_BAD_ACCESS. Stack tracing does not help. Any clues how can I find the problem?

+3
source share
6 answers

I saw moments when this can happen when you are trying to access an object that you did not save properly so that it does not point to a valid copy of your object or its pointing to an object of a different type. Placing early points and analyzing objects when entering the system using po and printing in gdb is the best choice.

+5
source

This usually indicates a memory management error.

, :

@interface MyClass : MySuperclass {
    UIClass *myOutlet;
}
@property (nonatomic, retain) IBOutlet UIClass *myOutlet;
@end

, .

awakeFromNib, , ..

+2

... XCode 4 EXC_BAD_ACCESS ( XCode "/" "" ). , .

+1

: - " "; . : (

0

(// .app). , - , , .

0

This is one of the possible reasons. There is an IBOutlet object that is not initialized, and the message is called on nil. The stack trace may look like this:

#0    0x90a594c7 in objc_msgSend
#1    0xbffff7b8 in ??
#2    0x932899d8 in loadNib
#3    0x932893d9 in +[NSBundle(NSNibLoading) _loadNibFile:nameTable:withZone:ownerBundle:]
#4    0x9328903a in +[NSBundle(NSNibLoading) loadNibFile:externalNameTable:withZone:]
#5    0x93288f7c in +[NSBundle(NSNibLoading) loadNibNamed:owner:]
#6    0x93288cc3 in NSApplicationMain
#7    0x00009f80 in main at main.mm:17

Since stack tracing does not help, you have to go through the code to find the error. If for some reason you cannot set breakpoints at an early stage of execution, try inserting some Debugger (); calls to be split into a debugger.

-3
source

Source: https://habr.com/ru/post/1696886/


All Articles