mirror of
https://github.com/SFML/SFML.git
synced 2024-11-25 04:41:05 +08:00
[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.
This commit is contained in:
parent
84bd8c6c5b
commit
83306e72a2
@ -129,26 +129,10 @@ void ANativeActivity_onCreate(ANativeActivity* activity, void* savedState, size_
|
|||||||
//
|
//
|
||||||
// With libname being the library name such as "jpeg".
|
// With libname being the library name such as "jpeg".
|
||||||
|
|
||||||
// Initialize JNI
|
// Retrieve JNI environment and JVM instance
|
||||||
jint lResult;
|
|
||||||
jint lFlags = 0;
|
|
||||||
|
|
||||||
JavaVM* lJavaVM = activity->vm;
|
JavaVM* lJavaVM = activity->vm;
|
||||||
JNIEnv* lJNIEnv = activity->env;
|
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
|
// Retrieve the NativeActivity
|
||||||
jobject ObjectNativeActivity = activity->clazz;
|
jobject ObjectNativeActivity = activity->clazz;
|
||||||
jclass ClassNativeActivity = lJNIEnv->GetObjectClass(ObjectNativeActivity);
|
jclass ClassNativeActivity = lJNIEnv->GetObjectClass(ObjectNativeActivity);
|
||||||
@ -188,9 +172,6 @@ void ANativeActivity_onCreate(ANativeActivity* activity, void* savedState, size_
|
|||||||
std::string libName = getLibraryName(lJNIEnv, ObjectActivityInfo);
|
std::string libName = getLibraryName(lJNIEnv, ObjectActivityInfo);
|
||||||
void* handle = loadLibrary(libName.c_str(), 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
|
// Call the original ANativeActivity_onCreate function
|
||||||
activityOnCreatePointer ANativeActivity_onCreate = (activityOnCreatePointer)dlsym(handle, "ANativeActivity_onCreate");
|
activityOnCreatePointer ANativeActivity_onCreate = (activityOnCreatePointer)dlsym(handle, "ANativeActivity_onCreate");
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user