felHR85 / UsbSerial

Usb serial controller for Android
MIT License
1.78k stars 582 forks source link

JNI DETECTED ERROR IN APPLICATION: use of deleted global reference #294

Open mheyse opened 4 years ago

mheyse commented 4 years ago

Description

When unplugging an USB device while an app is communicating with the device it sometimes crashes. The error message in the crash report is:

JNI DETECTED ERROR IN APPLICATION: use of deleted global reference 0x27c6 from android.hardware.usb.UsbRequest android.hardware.usb.UsbDeviceConnection.native_request_wait(long)

Library version is com.github.felHR85:UsbSerial:6.1.0.

Steps to reproduce

Have an Android java application communicating with an USB serial adapter device. Remove the adapter while the app is communicating.

Expected result

The app handles the disconnect gracefully.

Actual result

While this work most of the time, in some instances the app crashes with the error

JNI DETECTED ERROR IN APPLICATION: use of deleted global reference 0x27c6 from android.hardware.usb.UsbRequest android.hardware.usb.UsbDeviceConnection.native_request_wait(long)

Log is attached.

usbserial_crash.log

viktor76525 commented 2 years ago

Had something similar. Found out it was always happening when uninstalled, installed while connected and run (asked for permissions), then disconnected. Fixed by asking for permissions later, once app fully loaded, other permissions were sorted and the main screen was visible.