EXC_BAD_ACCESS using ARC and can't track on si

2019-08-02 07:22发布

I have been building an app for a client and everything was going smoothly until I started getting this error. This is a unique situation, I've learned how to use instruments and NSZombie however I can't run instruments with NSZombieEnabled on the iPhone only on the simulator. I have to debug this problem in the iPhone because I'm using UIImagePicker to take a picture and the error happens shortly after I take the picture. I'm also using ARC so I can't set release or retain info at all, ARC forbids it, so I doubt its a double release or anything like that. There are 2 possible answers to this question.

1: Does anyone know if I can pass an image into UIImagePicker using photo booth? I could use instruments and NSZombie if I could get passes the camera screen.

2: Is there a way to detect what line would be causing the error without refactoring or commenting out code using the iPhone? Does anybody know an efficient way to track down bad_acces on the iPhone?

Keep in mind I am using ARC and cannot debug this on the simulator. If I take out the UIImagePicker control script the bug does not happen so I've narrowed it down to something in my CameraViewController class. I'm afraid I can't post any code due to a preexisting contract, you would have to be an employee to view source code.

Sorry about the limited information but really I'm looking for an answer about debugging not a direct solution to my exact code problem.

Going to post the backtrace(i think)

(gdb) bt
#0  0x339737e4 in objc_msgSend ()
#1  0x31b30140 in -[UIApplication sendAction:to:from:forEvent:] ()
#2  0x31b300e0 in -[UIApplication sendAction:toTarget:fromSender:forEvent:] ()
#3  0x31b300b2 in -[UIControl sendAction:to:forEvent:] ()
#4  0x31b2fe04 in -[UIControl(Internal) _sendActionsForEvents:withEvent:] ()
#5  0x31b30452 in -[UIControl touchesEnded:withEvent:] ()
#6  0x31b2eddc in -[UIWindow _sendTouchesForEvent:] ()
#7  0x31b2e756 in -[UIWindow sendEvent:] ()
#8  0x31b299fe in -[UIApplication sendEvent:] ()
#9  0x31b29336 in _UIApplicationHandleEvent ()
#10 0x3026c04a in PurpleEventCallback ()
#11 0x3443fce2 in __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ ()
#12 0x3443fca6 in __CFRunLoopDoSource1 ()
#13 0x3443256c in __CFRunLoopRun ()
#14 0x34432276 in CFRunLoopRunSpecific ()
#15 0x3443217e in CFRunLoopRunInMode ()
#16 0x3026b5f2 in GSEventRunModal ()
#17 0x3026b69e in GSEventRun ()
#18 0x31ad0122 in -[UIApplication _run] ()
#19 0x31ace12e in UIApplicationMain ()
#20 0x000034ce in main (argc=1, argv=0x2ffff75c) at /Users/Andrew/Documents/Developing/Xcode Projects/ProjectSVN/Project/trunk/ProjectInterface/ProjectInterface/main.m:16

2条回答
时光不老,我们不散
2楼-- · 2019-08-02 07:30

Without code samples it is hard to say, however ARC doesn't totally cover all of your bases. For example, it is possible to get these EXC_BAD_ACCESS errors when objects (classes with delegates) do not exist, yet try to execute callback delegate methods.

To be more specific, let's say I have created a class in viewDidLoad: - let's call it ClassA. In my hypothetical situation, I set my view controller to ClassA's delegate. However, I have not declared a property for ClassA, so there is no reference to it beyond the scope of viewDidLoad:.

Now let's assume ClassA declare a delegate method that is implemented by my view controller. This delegate passes a reference of itself back to the view controller in this delegate method. Because it may or may not be out of scope by this point, BOOM, bad access error. Check for things such as this, where objects do not exist anymore and are being passed to other methods - it is one such way ARC can fail you ;)

查看更多
神经病院院长
3楼-- · 2019-08-02 07:35

EXC_BAD_ACCESS doesn't necessarily mean a memory management problem. It could just as easily be caused by memory corruption or other kinds of errors.

Post the backtrace of the crash.

查看更多
登录 后发表回答