libpd / pd-for-android

Pure Data for Android
353 stars 91 forks source link

pollPdMessageQueue either causes DeleteLocalRef from wrong thread, or SIGSEGV null pointer #100

Open mathieulb opened 4 years ago

mathieulb commented 4 years ago

JNI DETECTED ERROR IN APPLICATION: "PdNetsend.serverThread" using JNIEnv* from "PdNetsend.receiveThread" in call to DeleteLocalRef ... from void org.puredata.core.PdBase.pollPdMessageQueue()

In my app, I have the libpd thread, the main thread, and two java socket threads for custom versions of netsend and netreceive respectively, because I couldn't get those of libpd to work. Apparently pollPdMessageQueue tries to call DeleteLocalRef on things that aren't local refs. It sounds like having one global data structure that relies on pollPdMessageQueue always being considered a "critical section" (mutexed zone, e.g. like what sys_lock is for) even though there is no enforcement for it.

I tried wrapping pollPdMessageQueue() in a synchronized method so that it can only run once at a time (all polling goes through that method now), but now it gives this error instead : « signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x0 ; Cause: null pointer dereference »

This happens within 3 seconds of having closed a patch and reopened a patch while sending to and receiving from a remote patch using my java netsend/netreceive. Perhaps also in some other cases too. But now I've worked around the crash by removing a poll that was superfluous anyway.

This is both when using the 20190613 snapshot that we've been using for the past year, and the new 20200517 snapshot I installed yesterday.