0

Im using ZXing framework to make an barcode image out of a string. When i try it on the simulator it work, but when I try it on a device, I get a bad access error

ZXMultiFormatWriter *writer = [ZXMultiFormatWriter writer];
    ZXBitMatrix* result = [writer encode:self.discountProgramInfo.customerID
                                  format:self.barcodeFormat
                                   width:self.barcodeImageView.frame.size.width
                                  height:self.barcodeImageView.frame.size.height
                                   error:&error];
    if (result) {

        CGImageRef image = [[ZXImage imageWithMatrix:result] cgimage];
        self.barcodeImageView.image = [UIImage imageWithCGImage:image];
        // This CGImageRef image can be placed in a UIImage, NSImage, or written to a file.
    } else {
        NSString *errorMessage = [error localizedDescription];
        DLog("%@",errorMessage);
    }

It fails on this line: self.barcodeImageView.image = [UIImage imageWithCGImage:image]; and the CGImageRef is not generated properly.

Any ideas what could be causing the mismatch?

Yoav Schwartz
  • 2,017
  • 2
  • 23
  • 43
  • The function encode:format:width:height:error: takes an NSError parameter by reference. Have you checked the error? – Duncan C Jun 03 '14 at 13:58
  • Also, how can you both crash with a bad access ERROR and have the CGImageRef not created properly? If your app crashes, how can you see if the image ref is generated or not? – Duncan C Jun 03 '14 at 13:59
  • Because I put a break point when its created, but before I use it.when inspecting the CGImageRef(using the little eye icon that pops up when you hover) On the simulator I get a nice picture of a barcode, on the device I get a picture of nothing. The error is empty. – Yoav Schwartz Jun 03 '14 at 14:02
  • But I thought you said you crash with a bad access error? Once your app crashes, the values in your app's variables are not trustworthy. – Duncan C Jun 03 '14 at 14:04
  • It crashes on self.barcodeImageView.image = [UIImage imageWithCGImage:image]; I inspect the image one step before, right after creation – Yoav Schwartz Jun 03 '14 at 14:05
  • Ok, now we're getting somewhere. Is the CGImageRef == NULL? You should probably add code to check the CGImageRef for NULL before passing it to `imageWithCGImage:` – Duncan C Jun 03 '14 at 14:08
  • That's the thing, its not null, just unImagable or something. I will retrace some of my steps and post a followup – Yoav Schwartz Jun 03 '14 at 14:13
  • @DuncanC After some checking, I made sure the error is indeed nil, and the CGImageRef has some value, when I log the result, it looks like a a barcode. I'm running out of ideas what could be going wrong. – Yoav Schwartz Jun 04 '14 at 08:21

0 Answers0