我正在尝试将静态方法从 C++ 调用到 Java。但我收到以下错误:
D/cocos2d-x debug info(29160): isInternetConnected Done, value is: 1
A/libc(29160): @@@ ABORTING: INVALID HEAP ADDRESS IN dlfree
A/libc(29160): Fatal signal 11 (SIGSEGV) at 0xdeadbaad (code=1)
代码是:
bool InterfaceJNI::isInternetConnected()
{
JavaVM* jvm = JniHelper::getJavaVM();
int status;
JNIEnv *env;
jmethodID mid;
jobject jobj;
bool isAttached = false;
bool returnValue = false;
CCLog("InterfaceJNI isInternetConnected");
// Get Status
status = jvm->GetEnv((void **) &env, JNI_VERSION_1_6);
if(status < 0)
{
CCLog("isInternetConnected Status < 0 Failed to get JNI Enviroment!!!");
status = jvm->AttachCurrentThread(&env, NULL);
CCLog("isInternetConnected Status 2: %d", status);
if(status < 0)
{
CCLog("isInternetConnected Status < 0 !!!");
return false;
}
isAttached = true;
CCLog("isInternetConnected Status isAttached: %d", isAttached);
}
CCLog("isInternetConnected Status: %d", status);
CCLog("isInternetConnected Finding Class....");
jclass mClass = env->FindClass("org/example/SocialNetwork/CCSocialNetwork");
// Get Static bool isInternetConnection()
CCLog("isInternetConnected Getting method....");
mid = env->GetStaticMethodID(mClass, "isInternetConnection", "()Z");
if (mid == 0)
{
CCLog("isInternetConnected FAIL GET METHOD STATIC");
return false;
}
CCLog("isInternetConnected Calling method....");
// Call Static bool isInternetConnection()
jboolean jReturnValue = env->CallStaticBooleanMethod(mClass,mid);
CCLog("Call done ");
// Convert value from Java to C++
returnValue = (bool)jReturnValue;
CCLog("isInternetConnected Done, value is: %d", returnValue);
if(isAttached)
jvm->DetachCurrentThread();
// Change for return value
return returnValue;
}
但如果我只是:
// Call Static bool isInternetConnection()
/*jboolean jReturnValue =*/ env->CallStaticBooleanMethod(mClass,mid);
CCLog("Call done ");
// Convert value from Java to C++
//returnValue = (bool)jReturnValue;
CCLog("isInternetConnected Done, value is: %d", returnValue);
if(isAttached)
jvm->DetachCurrentThread();
// Change for return value
return returnValue;
我得到:
Fatal signal 7 (SIGBUS) at 0x00000000 (code=128)
所以我假设我打的电话没问题。
我在 C++ 中,我必须释放 jboolean 还是其他方法?