Why does this c++ (NDK) thread brings the whole program down ?
{
sleep(2);
// The JNIEnv
JNIEnv* jenv = NULL;
// attach thread to running JVM
int err = jvm->AttachCurrentThread(&jenv, NULL);
char szerr[256];
sprintf(szerr, "AttachCurrentThread() returned: %d", err);
__android_log_print(ANDROID_LOG_ERROR, "MYPROG", szerr);
jvm->DetachCurrentThread();
sleep (5);
}
szerr is 0, and the program would not abort if I do not AttachCurrentThread. The abortion
happens without any error being indicated in console / logcat.
Any help?
Check this out:
http://comments.gmane.org/gmane.comp.handhelds.android.ndk/4687
Perhaps you should use
GetEnv()to see if the environment is setup, before callingAttachCurrentThread()(otherwise no need to). More info here.