Android & Unity : Threads crash while using customed plugin

Hi everybody,

I have developped my own bluetooth plugin with Android Studio and I am now trying to embed it into an app that is basically supposed to communicate with a bluetooth device. This plugin has got one thread to listen and raise an event (DataOnReceived) for available bytes on the socket inputstream. Meanwhile, I am supposed to run two other threads from my C# code. In few words, one of them is supposed to send all requests from the UI to my device and the other retrieves the array of bytes from the event.

Unity version : 2019.1.8f1
Android Studio version : 3.5

I have seen few similar questions but none of them have worked for me so I am stuck with following issue. I have tried to compile with IL2CPP and Mono on my Samsung A8 with Android 9.0 Pie. Whenever I start my two threads, these errors are shown in my logcat (IL2CPP compilation). Look at the attached file.

Result with addr2line :
00d52e94
physx::Gu::SinglePersistentContactManifold::reduceBatchContactsConvex(physx::Gu::MeshPersistentContact const*, unsigned int, physx::Gu:: PCMContactPatch&)
??:?
00d58760
GeomMTDCallback_SphereConvex(physx:: PxVec3&, float&, physx:: PxGeometry const&, physx:: PxTransform const&, physx:: PxGeometry const&, physx:: PxTransform const&)
??:?

Any help would be very much appreciated,
Thank you !
Meven

4897382–477407–Logcat_Patient.txt (66.4 KB)

I have finally solved this !
JNI ERROR (app bug): accessed stale Local 0x1 (index 0 in a table of size 0) means that I try to access a memory address that might not be allocated anymore, check following link for further details :
Android Developers Blog: JNI Local Reference Changes in ICS).

So I need to attach my threads to AndroidJNI as follow :

2 Likes