kellogs
kellogs

Reputation: 2857

Android NDK thread aborts program

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?

Upvotes: 0

Views: 1373

Answers (1)

Peter Teoh
Peter Teoh

Reputation: 6713

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 calling AttachCurrentThread() (otherwise no need to). More info here.

Upvotes: 1

Related Questions