yeahdongcn / RSBarcodes_Swift

1D and 2D barcodes reader and generators for iOS 8 with delightful controls. Now Swift.
MIT License
710 stars 185 forks source link

App crashing when resizeImage is called #60

Open bdrelling opened 8 years ago

bdrelling commented 8 years ago

We're getting some crashes in our live app.

RSCodeGenerator.swift line 210 static RSAbstractCodeGenerator.resizeImage(UIImage, scale : CGFloat) -> UIImage

Crashed: com.apple.main-thread EXC_BREAKPOINT 0x00000001010f1d14

    public class func resizeImage(source:UIImage, scale:CGFloat) -> UIImage {
        let width = source.size.width * scale
        let height = source.size.height * scale

        UIGraphicsBeginImageContext(CGSizeMake(width, height))
        let context = UIGraphicsGetCurrentContext()
        CGContextSetInterpolationQuality(context, CGInterpolationQuality.None)
        source.drawInRect(CGRectMake(0, 0, width, height))
        let target = UIGraphicsGetImageFromCurrentImageContext()
        UIGraphicsEndImageContext()
        return target
    }
yeahdongcn commented 8 years ago

Could you provide me more information?

getaaron commented 7 years ago

EXC_BREAKPOINT can appear in production Swift code if something is unexpectedly nil. I'm guessing this happened because context was nil (in the current version of RSBarcodes_Swift, it's safely unwrapped)

DamienBallenghien commented 5 years ago

Safely unwrapped but when the context is nil, this function is returning nil .. :/

TonnyCS commented 11 months ago

The same happens to me from iOS 17.1.2.

// Barcode generation for client card
    func generateBarcode(
        using barcodeString: String?,
        size: CGSize
    ) -> UIImage? {
        guard
            let barcodeString,
            // Only ean13 check
            barcodeString.count == 13,
            let image = RSUnifiedCodeGenerator.shared.generateCode(
                barcodeString,
                machineReadableCodeObjectType: AVMetadataObject.ObjectType.ean13.rawValue
            )
        else {
            return nil
        }

        return RSAbstractCodeGenerator.resizeImage(image, targetSize: size, contentMode: .scaleToFill)
    }
image