januslo / react-native-bluetooth-escpos-printer

React-Native plugin for the bluetooth ESC/POS & TSC printers.
MIT License
361 stars 420 forks source link

QRcode not printed in production ios, app crashes #56

Open KBepo opened 5 years ago

KBepo commented 5 years ago

Hello, I am building an app for printing tickets with QR code and using this module. When the app is used in development mode, everything is working fine, but when I create an .ipa printing starts and works until it's time to print the QR code, at that moment printing stops and the app crashes. Here is the device log from the crash:

Exception Type: EXC_BAD_ACCESS (SIGSEGV) Exception Subtype: KERN_INVALID_ADDRESS at 0x0000000000000020 VM Region Info: 0x20 is not in any region. Bytes before following region: 4307877856 REGION TYPE START - END [ VSIZE] PRT/MAX SHRMOD REGION DETAIL UNUSED SPACE AT START --->
__TEXT 0000000100c50000-0000000100e50000 [ 2048K] r-x/r-x SM=COW ...app/AppName

Termination Signal: Segmentation fault: 11 Termination Reason: Namespace SIGNAL, Code 0xb Terminating Process: exc handler [475] Triggered by Thread: 0

P.S. I think the problem lies somewhere within this line of code in RNBluetoothEscposPrinter.m: uint8_t * graImage = [ImageUtils imageToGreyImage:[UIImage imageWithCGImage:image]];

When i commented this line the app didn't crash, but still couldn't print because it's missing this.

KBepo commented 5 years ago

I found the solution, this line: uint8_t * graImage = [ImageUtils imageToGreyImage:[UIImage imageWithCGImage:image]]; should be replaced with this: uint8_t * graImage = [ImageUtils imageToGreyImage:[[UIImage alloc] initWithCGImage:[[ZXImage imageWithMatrix:result] cgimage]]];

Also, by using this you don't need line: CGImageRef image = [[ZXImage imageWithMatrix:result] cgimage];

This is in file RNBluetoothEscposPrinter.m line 542.

@januslo please add this to your module as soon as possible to prevent crashing in release mode on ios