woocommerce / woocommerce-ios

WooCommerce iOS app
https://www.woocommerce.com/mobile
GNU General Public License v2.0
299 stars 110 forks source link

[Mobile Payments] [Crash] Attempting to print a second receipt crashes the app #5574

Closed allendav closed 2 years ago

allendav commented 2 years ago

If you attempt to print a receipt again after successfully printing it, the app crashes with unrecognized selector

2021-12-01 13:30:41.625947-0800 WooCommerce[5836:4229382] 🔵 Tracked receipt_print_tapped, properties: [AnyHashable("blog_id"): 197907611, AnyHashable("is_wpcom_store"): false]
2021-12-01 13:30:41.681880-0800 WooCommerce[5836:4228643] -[PKPrinter _internalPrinter]: unrecognized selector sent to instance 0x281dfd7a0
2021-12-01 13:30:41.686838-0800 WooCommerce[5836:4228643] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[PKPrinter _internalPrinter]: unrecognized selector sent to instance 0x281dfd7a0'
*** First throw call stack:
(0x18164604c 0x199cbaf54 0x181723014 0x1815db474 0x1815da5b0 0x18494ff00 0x18494bf44 0x18497c9d4 0x184977e3c 0x1849829f8 0x184977d68 0x1077a1150 0x1077a1878 0x10b99ed94 0x10b99a674 0x10bab1718 0x10b983024 0x10b98281c 0x1024b8b10 0x1024b8c5c 0x102b54ec0 0x102b568cc 0x1027492c0 0x102aedccc 0x10264145c 0x102641498 0x183f1bbf0 0x1058f8760 0x1841fab80 0x1841e4880 0x1841e4730 0x183f1bbf0 0x1058f8760 0x184047a4c 0x183dc32c8 0x183dc3318 0x1840f27c0 0x183bc607c 0x183bf7a84 0x183da7318 0x183bcac30 0x183bbfa1c 0x183bc4ec8 0x181668020 0x181678ce0 0x1815b2fe8 0x1815b87f4 0x1815cc3b8 0x19cf5c38c 0x183f6c6a8 0x183ceb7f4 0x1027de788 0x104a89a24)
libc++abi: terminating with uncaught exception of type NSException
dyld4 config: DYLD_LIBRARY_PATH=/usr/lib/system/introspection DYLD_INSERT_LIBRARIES=/Developer/usr/lib/libBacktraceRecording.dylib:/Developer/usr/lib/libMainThreadChecker.dylib:/Developer/Library/PrivateFrameworks/DTDDISupport.framework/libViewDebuggerSupport.dylib
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[PKPrinter _internalPrinter]: unrecognized selector sent to instance 0x281dfd7a0'
terminating with uncaught exception of type NSException

To Reproduce Steps to reproduce the behavior:

  1. Go to an order that has been paid for with In-Person Payments
  2. Tap on See Receipt
  3. Tap on the printer icon in the upper right
  4. Print the receipt
  5. Tap on the printer icon again
  6. Attempt to print the receipt again
  7. See error

Screenshots

Expected behavior The expected behavior is that the app should not crash, but allow more receipts to be printed.

Isolating the problem (mark completed items with an [x]):

Mobile Environment Please include:

WordPress Environment N/A

allendav commented 2 years ago

It is happening on the main thread. It happens on both iPads and iPhones

Screen Shot 2021-12-01 at 2 30 46 PM
allendav commented 2 years ago

I found the likely source of the problem. The UIPrintInfo passed to printController mutates after the first printing (e.g. _printerID is set to the printer we just printed to). Passing a fresh UIPrintInfo to the the printController right before present avoids the exception.