XCode - EXC_BAD_ACCESS. -[Not A Type retain]

2019-07-22 01:47发布

问题:

I'm trying to include this barcode source code by Stefanhafeneger to my project. I started it with a simple camera example and the barcode engine, everything works fine for the 1st barcode decode. When I try with the 2nd times, i receive EXC_BAD_ACCESS. It only work 1 time after that the application will crash.

Here is a screen recording of how the appilcation crash.

i'm testing with this DataMatrix tag from google in my appilcation.

i was surfing for solution for few days, I had tried NSZombieEnabled, and debug with Instrument but i still have no luck with it. The image below is the error from xcode.

*** -[Not A Type retain]: message sent to deallocated instance 0x7b21ed0

For your information it is an ARC enabled project. Someone please help, I'm still a few months old beginner.

Here is my xCode file for this project Barcode-Datamatrix Project

Update : I also tried disabling ARC for every file related to that library by Using the linker flag -fno-objC-arc but the result still the same. Besides i tried imageView.image = [UIImage imageWithCGImage:image.CGImage]; or a copy imageView.image = [image copy]; the application still crash at the same place.

Many Thanks Kin

回答1:

[Not A Type retain] indicates that you are passing an object that is not a UIImage to the UIImageView's image property, then the method attempts to discern it's type to send retain at the imagevVew.image = image line. NSLog it's type with NSLog("%@", NSStringFromClass([image class]));

EDIT: I Do Not recommend that you convert such an old project to ARC (and I quote: "It is linked against ios 2.1"). Use the linker flag -fno-objC-arc and disable ARC for every file related to that project. Afterwards, check that your imageView isn't funky, try setting your image to nil, or delete the line altogether and run.



回答2:

It may that BarCode Engine would not ARC enabled.

to disable some files which are not design for ARC support we can show to compiler that let it be ARC disable through this command

-fno-objc-arc

put this command on project build phases where all compiled source present ( i.e. all class in your project name will show)

ZBarSDK is quite simple and easy to use and more powerful API for this barcode, qr code decoding.