Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

Callbacks from another thread

21 views
Skip to first unread message

Davidson, Josh

unread,
Dec 6, 2021, 8:37:36 PM12/6/21
to javacpp...@googlegroups.com
We have a number of interface classes that we’ve bound using the Info.virtualize technique in the parser to make them callable from our native code. This works great except for one type of callback that is ultimately invoked from a thread that is started within the native code. When the native code invokes the callback interface, we get the following error: “Could not attach the JavaVM to the current thread.” Are there any workarounds that would enable the Java callbacks to be invoked from these threads?

Samuel Audet

unread,
Dec 6, 2021, 9:48:26 PM12/6/21
to javacpp...@googlegroups.com, Davidson, Josh
That sounds like an issue with JNI. I've never heard of anyone having
that problem, but it's failing on AttachCurrentThread() here:
https://github.com/bytedeco/javacpp/blob/master/src/main/java/org/bytedeco/javacpp/tools/Generator.java#L1435

I don't know what would make that call fail. It looks like insufficient
stack space could be one cause:
https://stackoverflow.com/questions/36486298/jni-attachcurrentthread-returns-1

So increasing the stack size of that thread might do the trick.

Samuel

josh.d...@lmco.com

unread,
Dec 6, 2021, 11:50:23 PM12/6/21
to javacpp
Thanks, that was exactly the problem (stack overflow).
Reply all
Reply to author
Forward
0 new messages