Note that there are some explanatory texts on larger screens.

plurals
  1. POjni - app crashing
    primarykey
    data
    text
    <p>This is a question related to the NDK and Android SDK. Currently, my C-code is calling a method defined in Java. This method is called callFromNDK().</p> <p>Within this method, i am referencing an instance of the mediaplayer to play a short test tone. callFromNDK() get's called every 2 secs. And the test tone itself is one sec.</p> <p>What i see is a (SIGSEGV), code 1 (SEGV_MAPERR), fault addr fffffff4 at times.</p> <p>I am wondering if this is happening because the mediaplayer instance was created in a different context than the one that it's getting used in?</p> <p>Here's the relevant piece of code [Java file]</p> <pre><code>public class Canvastutorial extends Activity { private static MediaPlayer mediaPlayer = null; public void callFromNDK() { if (mediaPlayer != null) { mediaPlayer.start(); } } @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mediaPlayer = MediaPlayer.create(getApplicationContext(), R.raw.audioclip); mediaPlayer.setLooping(false); } @Override protected void onDestroy() { mediaPlayer.release(); mediaPlayer = null; System.gc(); super.onDestroy(); } @Override protected void onPause() { stopAndPrepare(); super.onPause(); } private void stopAndPrepare() { mediaPlayer.stop(); try { mediaPlayer.prepare(); } catch (IllegalStateException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } mediaPlayer.seekTo(0); } } </code></pre> <p>The LogCat is as below when the app crashes:</p> <pre><code>04-27 10:42:13.228: I/DEBUG(8926): Build fingerprint: 'google/passion/passion:2.3.6/GRK39F/189904:user/release-keys' 04-27 10:42:13.228: I/DEBUG(8926): pid: 10362, tid: 11222 &gt;&gt;&gt; &lt;package_name&gt; &lt;&lt;&lt; 04-27 10:42:13.228: I/DEBUG(8926): signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr fffffff4 04-27 10:42:13.238: I/DEBUG(8926): r0 4214cdc0 r1 00000000 r2 00000000 r3 0000ce68 04-27 10:42:13.238: I/DEBUG(8926): r4 44628398 r5 00000000 r6 4472fbd8 r7 0000000e 04-27 10:42:13.238: I/DEBUG(8926): r8 80018000 r9 00000000 10 00000000 fp 800a5368 04-27 10:42:13.238: I/DEBUG(8926): ip 00000000 sp 4472fb88 lr 8001d084 pc 8001d090 cpsr 60000010 04-27 10:42:13.238: I/DEBUG(8926): d0 00650072006800b8 d1 00000044bed7f457 04-27 10:42:13.238: I/DEBUG(8926): d2 0069006400650052 d3 004d0049002e0040 04-27 10:42:13.238: I/DEBUG(8926): d4 0061006900640065 d5 00790061006c0050 04-27 10:42:13.238: I/DEBUG(8926): d6 0065005300720065 d7 0063006900760072 04-27 10:42:13.238: I/DEBUG(8926): d8 0000000000000000 d9 0000000042ba56de 04-27 10:42:13.238: I/DEBUG(8926): d10 0000000000000000 d11 0000000000000000 04-27 10:42:13.238: I/DEBUG(8926): d12 0000000000000000 d13 0000000000000000 04-27 10:42:13.238: I/DEBUG(8926): d14 0000000000000000 d15 0000000000000000 04-27 10:42:13.238: I/DEBUG(8926): d16 0000000000000001 d17 c053000000000000 04-27 10:42:13.238: I/DEBUG(8926): d18 0000000000000000 d19 0000000000000000 04-27 10:42:13.238: I/DEBUG(8926): d20 3ff0000000000000 d21 8000000000000000 04-27 10:42:13.238: I/DEBUG(8926): d22 0000000000000000 d23 ff00000000000000 04-27 10:42:13.238: I/DEBUG(8926): d24 ff00000000000000 d25 ff00000000000000 04-27 10:42:13.238: I/DEBUG(8926): d26 0100010001000100 d27 0100010001000100 04-27 10:42:13.238: I/DEBUG(8926): d28 0100010001000100 d29 3ff0000000000000 04-27 10:42:13.238: I/DEBUG(8926): d30 0000000000000000 d31 3ff0000000000000 04-27 10:42:13.238: I/DEBUG(8926): scr 60000012 04-27 10:42:13.328: I/DEBUG(8926): #00 pc 0001d090 /system/lib/libdvm.so 04-27 10:42:13.328: I/DEBUG(8926): #01 pc 000220e4 /system/lib/libdvm.so 04-27 10:42:13.328: I/DEBUG(8926): #02 pc 00020fdc /system/lib/libdvm.so 04-27 10:42:13.328: I/DEBUG(8926): #03 pc 0005fc40 /system/lib/libdvm.so 04-27 10:42:13.328: I/DEBUG(8926): #04 pc 0004cff8 /system/lib/libdvm.so 04-27 10:42:13.328: I/DEBUG(8926): #05 pc 00001590 /data/data/&lt;package_name&gt;/lib/libtest-jni.so 04-27 10:42:13.328: I/DEBUG(8926): #06 pc 000016ca /data/data/&lt;package_name&gt;/lib/libtest-jni.so 04-27 10:42:13.328: I/DEBUG(8926): #07 pc 000118e4 /system/lib/libc.so 04-27 10:42:13.328: I/DEBUG(8926): #08 pc 000114b0 /system/lib/libc.so 04-27 10:42:13.328: I/DEBUG(8926): code around pc: 04-27 10:42:13.328: I/DEBUG(8926): 8001d070 fa0108cc ea000017 e3a00001 e3a09000 04-27 10:42:13.328: I/DEBUG(8926): 8001d080 ebffff72 e2450014 e5905000 e5909004 04-27 10:42:13.328: I/DEBUG(8926): 8001d090 e515200c e5963018 e3520000 1592a000 04-27 10:42:13.328: I/DEBUG(8926): 8001d0a0 e3a01000 0affff8a e1f970b6 e5862010 04-27 10:42:13.328: I/DEBUG(8926): 8001d0b0 e59a1028 e5835028 e590a010 e1a04009 04-27 10:42:13.328: I/DEBUG(8926): code around lr: 04-27 10:42:13.328: I/DEBUG(8926): 8001d064 e088f30c e1a01000 e5960018 fa0108cc 04-27 10:42:13.328: I/DEBUG(8926): 8001d074 ea000017 e3a00001 e3a09000 ebffff72 04-27 10:42:13.328: I/DEBUG(8926): 8001d084 e2450014 e5905000 e5909004 e515200c 04-27 10:42:13.328: I/DEBUG(8926): 8001d094 e5963018 e3520000 1592a000 e3a01000 04-27 10:42:13.328: I/DEBUG(8926): 8001d0a4 0affff8a e1f970b6 e5862010 e59a1028 04-27 10:42:13.328: I/DEBUG(8926): stack: 04-27 10:42:13.328: I/DEBUG(8926): 4472fb48 4472fbe0 04-27 10:42:13.328: I/DEBUG(8926): 4472fb4c 4214cce4 04-27 10:42:13.328: I/DEBUG(8926): 4472fb50 0000ce60 04-27 10:42:13.328: I/DEBUG(8926): 4472fb54 00000001 04-27 10:42:13.328: I/DEBUG(8926): 4472fb58 4472fbe0 04-27 10:42:13.338: I/DEBUG(8926): 4472fb5c 80049697 /system/lib/libdvm.so 04-27 10:42:13.338: I/DEBUG(8926): 4472fb60 4214cce4 04-27 10:42:13.338: I/DEBUG(8926): 4472fb64 431fbec9 04-27 10:42:13.338: I/DEBUG(8926): 4472fb68 ad34675d /system/lib/libandroid_runtime.so 04-27 10:42:13.338: I/DEBUG(8926): 4472fb6c 4472fbe0 04-27 10:42:13.338: I/DEBUG(8926): 4472fb70 42f8e91e 04-27 10:42:13.338: I/DEBUG(8926): 4472fb74 4214cd00 04-27 10:42:13.338: I/DEBUG(8926): 4472fb78 4472fbd8 04-27 10:42:13.338: I/DEBUG(8926): 4472fb7c 40038360 04-27 10:42:13.338: I/DEBUG(8926): 4472fb80 df002777 04-27 10:42:13.338: I/DEBUG(8926): 4472fb84 e3a070ad 04-27 10:42:13.338: I/DEBUG(8926): #00 4472fb88 4214e32c 04-27 10:42:13.338: I/DEBUG(8926): 4472fb8c 4472fbd8 04-27 10:42:13.338: I/DEBUG(8926): 4472fb90 00000001 04-27 10:42:13.338: I/DEBUG(8926): 4472fb94 002c2c40 04-27 10:42:13.338: I/DEBUG(8926): 4472fb98 0000ce68 04-27 10:42:13.338: I/DEBUG(8926): 4472fb9c 000f45b8 04-27 10:42:13.338: I/DEBUG(8926): 4472fba0 800aad38 04-27 10:42:13.338: I/DEBUG(8926): 4472fba4 fffffe84 04-27 10:42:13.338: I/DEBUG(8926): 4472fba8 800a5368 04-27 10:42:13.338: I/DEBUG(8926): 4472fbac 800220e8 /system/lib/libdvm.so 04-27 10:42:13.338: I/DEBUG(8926): #01 4472fbb0 4472fbd8 04-27 10:42:13.338: I/DEBUG(8926): 4472fbb4 0000ce60 04-27 10:42:13.338: I/DEBUG(8926): 4472fbb8 80022058 /system/lib/libdvm.so 04-27 10:42:13.338: I/DEBUG(8926): 4472fbbc 423298c8 04-27 10:42:13.338: I/DEBUG(8926): 4472fbc0 00000000 04-27 10:42:13.338: I/DEBUG(8926): 4472fbc4 80020fe0 /system/lib/libdvm.so </code></pre> <p>Any idea is appreciated.</p> <p>Thanks.</p> <p>The native side of the project: The thread_function get's called periodically (2 sec interval) and that's where i am calling the function defined in Java code.</p> <pre><code>// Callbacks to Android JavaVM *j_vm; jobject *j_obj; JNIEnv *j_env; jclass j_cls; jmethodID android_call; int JNI_OnLoad(JavaVM* vm, void* reserved) { j_vm = vm; (*j_vm)-&gt;GetEnv(j_vm, (void**) &amp;j_env, JNI_VERSION_1_6); j_cls = (*j_env)-&gt;FindClass(j_env, "&lt;package_name&gt;/&lt;class_name&gt;"); android_call = (*j_env)-&gt;GetMethodID(j_env, j_cls, "callFromNDK", "()V"); j_obj = (*j_env)-&gt;NewGlobalRef(j_env, (*j_env)-&gt;NewObject(j_env, j_cls, android_call)); return JNI_VERSION_1_6; } void JNI_OnUnload(JavaVM *vm, void *reserved) { (*j_env)-&gt;DeleteGlobalRef(j_env, j_obj); } void *thread_function(void *ptr) { int *which = (int *) ptr; (*j_vm)-&gt;AttachCurrentThread(j_vm, &amp;j_env, NULL); int rc; while (!stop_thread) { rc = pthread_mutex_lock(&amp;mtx); rc = pthread_cond_wait(&amp;cond, &amp;mtx); rc = pthread_mutex_unlock(&amp;mtx); if (!stop_thread) { (*j_env)-&gt;CallVoidMethod(j_env, j_obj, android_call); } } (*j_vm)-&gt;DetachCurrentThread(j_vm); return NULL; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. COWhat is calling thread_function? Regardless if it's the specific issue, I think you could add some logging and exception handling around the mediaPlayer.start() - also it has been prepared at that point, right? Worth a re-read of the mediaplyer docs.
      singulars
    2. COthread_function is a function pointer registered while i create a thread. This is function that gets called when the thread starts running. And yes, the mediaPlayer instance is created and non-null. The app runs for around 15 or 20 mins and then crashes. The length of time it takes for the app to crash is non deterministic. Having debug logs around mediaPlayer.start() isn't helping since that's not where the problem is. As @StarDust noted, the problem must be in my native code. Can you give me some guidelines on how to debug the native code other than putting log statements? Thx.
      singulars
    3. COThe problem may be in your code, but the dump indicates that the actual crash is in libdvm.so instead. So you need to figure out what your code might be doing to set the DVM up to crash. Logging the state of affairs at the last line of your code executed before the crash could help with that, particularly if it's a mis-use of the mediaPlayer object. To better identify the last point in your code use the address to line tool or objdump to identify the two points in libtest-jni.so that are mentioned in the stack dump. You can also set up GDB...
      singulars
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload