JNI ERROR (app bug): accessed stale local reference

Hi All,

I’m really new to cocos2d-x.

  1. Created a new hello world project with the RC1 code
  2. build native
  3. set targetSdkVersion = 11 in manifest
  4. run the app on my nexus 4

The above steps allow me to run the hello world OK.

Now if I change the targetSdkVersion to greater than 11, e.g. targetSdkVersion=14, this will crash the app.

Does this mean cocos2d-x RC1 does not support targetSdkVersion greater than 11?

Hi, do you have sucess? i’m having the same problem in android emulator

many thanks

hello, could you show the output of the logcat ?

Sorry about the cut in the lines, but this is the log

04-07 22:55:16.665: E/gralloc_goldfish(49): gralloc_alloc: Mismatched usage flags: 328 x 583, usage 333
04-07 22:55:16.665: E/(49): GraphicBufferAlloc::createGraphicBuffer(w=328, h=583) failed (Invalid argument), handle=0x0
04-07 22:55:16.675: E/BufferQueue(381): [ScreenshotClient] dequeueBuffer: SurfaceComposer::createGraphicBuffer failed
04-07 22:55:17.155: E/gralloc_goldfish(49): gralloc_alloc: Mismatched usage flags: 720 x 1280, usage b33
04-07 22:55:17.155: E/(49): GraphicBufferAlloc::createGraphicBuffer(w=720, h=1280) failed (Invalid argument), handle=0x0
04-07 22:55:17.155: E/BufferQueue(49): [ScreenshotSurface] dequeueBuffer: SurfaceComposer::createGraphicBuffer failed
04-07 22:55:18.125: E/dalvikvm(1157): JNI ERROR (app bug): accessed stale local reference 0x9a700029 (index 10 in a table of size 2)
04-07 22:55:18.175: E/dalvikvm(1157): VM aborting

Hi there,

The same crash here, using cocos2d-x-3.0rc1 as well but crash occurs starting from target sdk 14.
Crash log when running on Motorola Xoom (4.1.2):

04-08 06:30:32.240: D/dalvikvm(17888): Trying to load lib /data/data/com.zgames.mygame/lib/libcocos2dcpp.so 0x418fde88
04-08 06:30:32.250: D/dalvikvm(17888): Added shared lib /data/data/com.zgames.mygame/lib/libcocos2dcpp.so 0x418fde88
04-08 06:30:32.250: D/JniHelper(17888): JniHelper::setJavaVM(0x41307e78), pthread_self() = 1075885872
04-08 06:30:32.280: E/dalvikvm(17888): JNI ERROR (app bug): accessed stale local reference 0xe8400029 (index 10 in a table of size 2)
04-08 06:30:32.280: E/dalvikvm(17888): VM aborting
04-08 06:30:32.280: A/libc(17888): Fatal signal 11 (SIGSEGV) at 0xdeadd00d (code=1), thread 17901 (Thread-4824)
...

Stack trace is:

pid: 17888, tid: 17901, name: Thread-4824  >>> com.zgames.mygame <<<
signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr deadd00d
Stack frame #00  pc 00045dbc  /system/lib/libdvm.so (dvmAbort+75)
Stack frame #01  pc 00028bbc  /system/lib/libdvm.so (IndirectRefTable::get(void*) const+336)
Stack frame #02  pc 00049e57  /system/lib/libdvm.so (dvmDecodeIndirectRef(Thread*, _jobject*)+30)
Stack frame #03  pc 0004c7f5  /system/lib/libdvm.so
Stack frame #04  pc 00233d99  /data/data/com.zgames.mygame/lib/libcocos2dcpp.so (_JNIEnv::CallObjectMethod(_jobject*, _jmethodID*, ...)+18): Routine _JNIEnv::CallObjectMethod(_jobject*, _jmethodID*, ...) at /Users/nverenik/SDKs/android-ndk-r9c/platforms/android-9/arch-arm/usr/include/jni.h:636

Crash occurs in JniHelper.cpp at first call (line 168) of method jclass _getClassID(const char *className), line 44 (CallObjectMethod).
Class name is “org/cocos2dx/lib/Cocos2dxHelper”, method name is “getCocos2dxWritablePath”

So far I’ve just avoid this crash by not specifying target version :slight_smile:

– Nick

No. I don’y know enough details about Cocos2d-x … However, I did a bit search on the net and found what looks like the cause of the problem.

Maybe Cocos2d-x doesn’t implement the JNI correctly. I’m only guessing.

Hi,

Anyone have sucess or resolve this problem?, i try other stuffs but i’m not very good in java jni code and problem still remain,

Hi,I changed

JniHelper::classloader = cocos2d::JniHelper::getEnv()->NewGlobalRef(_c);

in JinHelper.cpp line 146, the bug fixed!

@mond03cn many thanks, finally i got work, just one line of code and everthing works,

i take the liberty to republish your answer to more people that have this problem too,
hope that bug will correct in future

Regards