From 83306e72a2f9a4ed5cd72848c6f4d4072b596795 Mon Sep 17 00:00:00 2001 From: Jonathan De Wachter Date: Tue, 11 Mar 2014 21:10:11 +0100 Subject: [PATCH] [Android] Don't attach the same thread twice to the JVM ANativeActivity_onCreate is called by NaviteActivity from Java (which is the main thread). Thus, this thread is already attached to the JVM. --- src/SFML/Main/SFMLActivity.cpp | 21 +-------------------- 1 file changed, 1 insertion(+), 20 deletions(-) diff --git a/src/SFML/Main/SFMLActivity.cpp b/src/SFML/Main/SFMLActivity.cpp index 686f574df..e0610cbda 100644 --- a/src/SFML/Main/SFMLActivity.cpp +++ b/src/SFML/Main/SFMLActivity.cpp @@ -129,26 +129,10 @@ void ANativeActivity_onCreate(ANativeActivity* activity, void* savedState, size_ // // With libname being the library name such as "jpeg". - // Initialize JNI - jint lResult; - jint lFlags = 0; - + // Retrieve JNI environment and JVM instance JavaVM* lJavaVM = activity->vm; JNIEnv* lJNIEnv = activity->env; - JavaVMAttachArgs lJavaVMAttachArgs; - lJavaVMAttachArgs.version = JNI_VERSION_1_6; - lJavaVMAttachArgs.name = "NativeThread"; - lJavaVMAttachArgs.group = NULL; - - // Attach the current thread to the JAva virtual machine - lResult=lJavaVM->AttachCurrentThread(&lJNIEnv, &lJavaVMAttachArgs); - - if (lResult == JNI_ERR) { - LOGE("Couldn't attach the current thread to the Java virtual machine"); - exit(1); - } - // Retrieve the NativeActivity jobject ObjectNativeActivity = activity->clazz; jclass ClassNativeActivity = lJNIEnv->GetObjectClass(ObjectNativeActivity); @@ -188,9 +172,6 @@ void ANativeActivity_onCreate(ANativeActivity* activity, void* savedState, size_ std::string libName = getLibraryName(lJNIEnv, ObjectActivityInfo); void* handle = loadLibrary(libName.c_str(), lJNIEnv, ObjectActivityInfo); - // todo: should we detach the current thread ? because if we do, it - // crashes (lJavaVM->DetachCurrentThread();) - // Call the original ANativeActivity_onCreate function activityOnCreatePointer ANativeActivity_onCreate = (activityOnCreatePointer)dlsym(handle, "ANativeActivity_onCreate");