Very Frustrating JniHelper Crash


#1

I am getting the following crash on app load:

********** Crash dump: ********** Build fingerprint: 'samsung/SPH-D710VMUB/SPH-D710VMUB:4.1.2/JZO54K/SPH-D710.GB28:user/release-keys' pid: 16609, tid: 16609, name: cos2dx.hellocpp >>> org.cocos2dx.hellocpp <<< signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 00000000 Stack frame #00 pc 00192524 /data/data/org.cocos2dx.hellocpp/lib/libhellocpp.so (_JavaVM::GetEnv(void**, int)+28): Routine getJNIEnv at /Users/egjoka/Documents/Projects/jezzball/samples/Cpp/HelloCpp/proj.android/../../../../CocosDenshion/android/jni/SimpleAudioEngineJni.cpp:37 Stack frame #01 pc 0026eb24 /data/data/org.cocos2dx.hellocpp/lib/libhellocpp.so: Routine getEnv at /Users/egjoka/Documents/Projects/jezzball/samples/Cpp/HelloCpp/proj.android/../../../../cocos2dx/platform/android/jni/JniHelper.cpp:68 Stack frame #02 pc 0026ed4c /data/data/org.cocos2dx.hellocpp/lib/libhellocpp.so: Routine getStaticMethodInfo_ at /Users/egjoka/Documents/Projects/jezzball/samples/Cpp/HelloCpp/proj.android/../../../../cocos2dx/platform/android/jni/JniHelper.cpp:136 Stack frame #03 pc 0026f118 /data/data/org.cocos2dx.hellocpp/lib/libhellocpp.so (cocos2d::JniHelper::getStaticMethodInfo(cocos2d::JniMethodInfo_&, char const*, char const*, char const*)+44): Routine openKeyboardJNI at /Users/egjoka/Documents/Projects/jezzball/samples/Cpp/HelloCpp/proj.android/../../../../cocos2dx/platform/android/jni/IMEJni.cpp:43 Stack frame #04 pc 0026dcf4 /data/data/org.cocos2dx.hellocpp/lib/libhellocpp.so (getBoolForKeyJNI(char const*, bool)+64): Routine getIntegerForKeyJNI(char const*, int) at /Users/egjoka/Documents/Projects/jezzball/samples/Cpp/HelloCpp/proj.android/../../../../cocos2dx/platform/android/jni/Java_org_cocos2dx_lib_Cocos2dxHelper.cpp:202 Stack frame #05 pc 00288dc4 /data/data/org.cocos2dx.hellocpp/lib/libhellocpp.so (cocos2d::CCUserDefault::getBoolForKey(char const*, bool)+40): Routine cocos2d::CCUserDefault::getFloatForKey(char const*, float) at /Users/egjoka/Documents/Projects/jezzball/samples/Cpp/HelloCpp/proj.android/../../../../cocos2dx/support/user_default/CCUserDefaultAndroid.cpp:234 Stack frame #06 pc 00111a7c /data/data/org.cocos2dx.hellocpp/lib/libhellocpp.so: Routine TGScoreLabel at /Users/egjoka/Documents/Projects/jezzball/samples/Cpp/HelloCpp/proj.android/jni/../../Classes/TGScoreLabel.cpp:11 Stack frame #07 pc 00111adc /data/data/org.cocos2dx.hellocpp/lib/libhellocpp.so: Routine TGScoreLabel at /Users/egjoka/Documents/Projects/jezzball/samples/Cpp/HelloCpp/proj.android/jni/../../Classes/TGScoreLabel.cpp:15 Stack frame #08 pc 00003753 /system/bin/linker Stack frame #09 pc 00005c4b /system/bin/linker Stack frame #10 pc 0004f65b /system/lib/libdvm.so (dvmLoadNativeCode(char const*, Object*, char**)+186) Stack frame #11 pc 000660f5 /system/lib/libdvm.so Stack frame #12 pc 000273a4 /system/lib/libdvm.so Stack frame #13 pc 000205b0 [stack]

Any help would be greatly appreciated. I have based the project on samplecpp and in main I have:

`
jint JNI_OnLoad(JavaVM *vm, void *reserved)
{
JniHelper::setJavaVM(vm);
return JNI_VERSION_1_2;
}

void Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeInit(JNIEnv* env, jobject thiz, jint w, jint h)
{
if (!CCDirector::sharedDirector()->getOpenGLView())
{
CCEGLView *view = CCEGLView::sharedOpenGLView();
view->setFrameSize(w, h);
AppDelegate *pAppDelegate = new AppDelegate();
CCApplication::sharedApplication()->run();
}
else
{
ccGLInvalidateStateCache();
CCShaderCache::sharedShaderCache()->reloadDefaultShaders();
ccDrawInit();
CCTextureCache::reloadAllTextures();
CCNotificationCenter::sharedNotificationCenter()->postNotification(EVENT_COME_TO_FOREGROUND, NULL);
CCDirector::sharedDirector()->setGLDefaultValues();
}
}
`

Thank you guys very much


JNI Multi-threaded Access Problems
#2

um…I guess it may be jni version’s problem, “JNIVERSION12” is a weired macro, what I see in my cocos2d-x version(2.2.2) is like this.
#define JNI_VERSION_1_1 0x00010001
#define JNI_VERSION_1_2 0x00010002
#define JNI_VERSION_1_4 0x00010004
#define JNI_VERSION_1_6 0x00010006
anyway, check it plz.


Featured Android game crashes in libcocos2dcpp.so
#3

I’ve tried all the different versions and still no go


#4

Hi,

Just wanted to confirm that I’m also getting JniHelper crashes. For me it’s on app exit though.
v2.2.1 did not have this problem.

Thanks


#5

Looking into this some more, it looks like getEnv() was changed in JniHelper.cpp
It seems that getEnv() now sets env as a thread specific variable and no longer supports multi-threaded access to the JNI. My guess is that it’s related to getEnv() using only one key for pthread_setspecific and not accounting for multiple threads calling getEnv(). I’m unfamiliar with pthread_setspecific, so I don’t have any suggestions at the moment other than rolling back to v2.2.1.

Perhaps we should submit this as a bug?


#6

Hi again,

I went ahead and submitted this as a bug: http://cocos2d-x.org/issues/3993

Thanks