title: Qt JNI : Invalid indirect reference 0x61382e48 in decodeIndirectRef
body: <p>I am trying the Qt project that captures audio data from mic on android.
  I refereed this article : <a href="https://stackoverflow.com/questions/8499042/android-audiorecord-example">Android AudioRecord example</a>, and wrote it to Qt code.</p>
  
  <pre><code>int recorderSampleRate = 44100;
  int recorderChannels = QAndroidJniObject::getStaticField&lt;jint&gt;("android/media/AudioFormat", "CHANNEL_IN_MONO");
  int recorderAudioEncoding =  QAndroidJniObject::getStaticField&lt;jint&gt;("android/media/AudioFormat", "ENCODING_PCM_16BIT");
  int sourceType = QAndroidJniObject::getStaticField&lt;jint&gt;("android/media/MediaRecorder$AudioSource", "MIC");
  
  
  int bsize = QAndroidJniObject::callStaticMethod&lt;int&gt;("android/media/AudioRecord", "getMinBufferSize", "(III)I", recorderSampleRate, recorderChannels, recorderAudioEncoding);
  
  mAudioRecorder = new QAndroidJniObject("android/media/AudioRecord", "(IIIII)V", sourceType, recorderSampleRate, recorderChannels, recorderAudioEncoding, BufferElements2Rec * BytesPerElement);
  
  
  // starting capture.
  mAudioRecorder-&gt;callMethod&lt;void&gt;("startRecording", "()V");
  
  // ready buffer.
  jint size = BufferElements2Rec * BytesPerElement;
  jbyte buffers[size * 2];
  
  qDebug() &lt;&lt; "start capture";
  
  while(true)
  {
      {
          jint offset = 0;
  
          // read cached audio data from AudioRecord
          int result = mAudioRecorder-&gt;callMethod&lt;jint&gt;("read", "([BII)I", buffers, offset, size);
  
          qDebug() &lt;&lt; "readed byte size " &lt;&lt; result;
      }
  
      // wait a bit for new audio data.
      msleep(10);
  }
  </code></pre>
  
  <p>But, at this line 
  <strong>int result = mAudioRecorder->callMethod("read", "([BII)I", buffers, offset, size);</strong> 
  the app crashed and outputted following log.</p>
  
  <pre><code>W/dalvikvm(24772): Invalid indirect reference 0x61382e48 in decodeIndirectRef
  E/dalvikvm(24772): VM aborting
  F/libc    (24772): Fatal signal 11 (SIGSEGV) at 0xdeadd00d (code=1), thread 24975 (ldAndroidCaptur)
  </code></pre>
  
  <p>I guessed this error was cause of bad JNI calling, but I couldn't find the reason.</p>
  
  <p><strong>Addition:</strong>
  I found <strong>0x61382e48</strong> is a <strong>address of buffers array</strong></p>
  
  <p>EDIT : Android guide for AudioRecord is <a href="http://developer.android.com/reference/android/media/AudioRecord.html#read%28java.nio.ByteBuffer,%20int%29" rel="nofollow noreferrer">here</a>.</p>
  
  <p>Welcome any advices.</p>