4

I 'm trying to call a Static method from C++ to Java. But I get the following error:

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)

The code is:

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;
}

But if I just:

// 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;

I get:

Fatal signal 7 (SIGBUS) at 0x00000000 (code=128)

So I assume that the call I making is ok.

I'm in C++, I must free the jboolean or another method?

vgonisanz
  • 11,831
  • 13
  • 78
  • 130
  • Hang on: you get "Fatal signal 7 (SIGBUS) at 0x00000000 (code=128)", and you assume that the call is OK? So you know where that fatal signal is coming from? – TonyK Apr 14 '13 at 21:09
  • I think you have either some threading issues or memory corruption. I don't think it has anything to do with your Java code. Can you show us how you compile and link the C++ code? – maba Apr 15 '13 at 07:19

1 Answers1

3

Is not needed to release the jboolean.

The C++ code is ok. But that signal 7 appear something is wrong with your Java code.

  • Check if you are using static classes with statics call.

If this is right, check where the code you are using is. Sometimes, internal calls can send SIGBUS, so try to use code only in your class.

  • Try step by step the code you are executing to check what is wrong.
goe
  • 2,272
  • 1
  • 19
  • 34