2

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.

UfoDesign DataMatrix

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

debugging1 debugging2

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

Kin
  • 171
  • 1
  • 14
  • I've never seen "Not A Type" before...can you confirm that the library you are using supports ARC? It seems that the image coming through the delegate method has already been deallocated by the time it reaches that line. – borrrden Apr 10 '12 at 00:54
  • I'm not sure about the library. I had removed all the release,retain,autorelease function from the library since my project is ARC enabled. Isn't possible to disable ARC in selected file? – Kin Apr 10 '12 at 02:04
  • It is definitely possible http://stackoverflow.com/questions/6646052/how-can-i-disable-arc-for-a-single-file-in-a-project Furthermore, simply removing all the retains and releases without checking logic is not a good idea. ARC might release things too soon. – borrrden Apr 10 '12 at 02:15
  • 1
    Do not modify the library by hand, it will get you in trouble. Follow the borrrden's link to disable ARC on a file basis. – lukasz Apr 10 '12 at 02:18
  • I had just tried -fno-objc-arc to disable the ARC for the original library but the result is still the same. It crashed at the sec try. – Kin Apr 10 '12 at 02:26
  • Try to make a new image object: `imageView.image = [UIImage imageWithCGImage:image.CGImage];` or a copy `imageView.image = [image copy];` – tipycalFlow Apr 10 '12 at 04:49
  • Thanks for your suggestion. Unfortunately it does not works... i think the problem is not under imageview but the image send to the barcode engin library. – Kin Apr 10 '12 at 06:11

2 Answers2

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.

CodaFi
  • 43,043
  • 8
  • 107
  • 153
  • Thanks for your reply, I tried NSLog("%@", NSStringFromClass([image class])); and i received UIImage type from the console before the crash. That's mean it's sending UIImage to the UIImageView. – Kin Apr 10 '12 at 02:08
  • 1
    Are you bridging it's type in any way? – CodaFi Apr 10 '12 at 03:30
1

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.

gauravds
  • 2,931
  • 2
  • 28
  • 45
  • I had tried with -fno-objc-arc but it does not work. I try ZBarSDK before, it is very easy but it does not support DataMatrix. – Kin Apr 10 '12 at 06:09