Android I2C crash

I'm getting periodic stack dumps talking to a gyro over I2C. The stack trace is below. 

07-10 04:19:50.138  28129-28129/com.mbientlab.metawear.app E/AndroidRuntime﹕ FATAL EXCEPTION: main
    Process: com.mbientlab.metawear.app, PID: 28129
    java.lang.RuntimeException: Error receiving broadcast Intent { act=com.mbientlab.com.metawear.api.MetaWearBleService.Action.NOTIFICATION_RECEIVED flg=0x10 (has extras) } in com.mbientlab.metawear.api.MetaWearBleService$2@41c01c40
            at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:788)
            at android.os.Handler.handleCallback(Handler.java:733)
            at android.os.Handler.dispatchMessage(Handler.java:95)
            at android.os.Looper.loop(Looper.java:137)
            at android.app.ActivityThread.main(ActivityThread.java:5082)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:782)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:598)
            at dalvik.system.NativeStart.main(Native Method)
     Caused by: java.lang.NegativeArraySizeException: -1
            at com.mbientlab.metawear.api.controller.I2C$Register$1.notifyCallbacks(I2C.java:57)
            at com.mbientlab.metawear.api.MetaWearBleService$2.onReceive(MetaWearBleService.java:343)
            at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:778)
            at android.os.Handler.handleCallback(Handler.java:733)
            at android.os.Handler.dispatchMessage(Handler.java:95)
            at android.os.Looper.loop(Looper.java:137)
            at android.app.ActivityThread.main(ActivityThread.java:5082)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:782)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:598)
            at dalvik.system.NativeStart.main(Native Method)

Comments

  • Can you consistently cause this crash?  The line in question is code that extracts the I2C data from the MetaWear response packet and the crash is caused the response being less than 3 bytes long.
  • My code is under heavy development. It was happening consistently before a change I made last night but has yet to occur since. I use a timer and an event to send gyro samples over I2C whenever a gpio is low. My previous code started the timer when the pin went low and stopped it when it returned high. I changed the code to post a read of the pin whenever I received a sample and stop the timer when it went high. The reason I made the change was I dropping low to high transitions for some reason causing the sample stream to remain on. I don't know if the problem went away but It hasn't happened since that change. I'll let you know if I see it again.
  • It just happened again. 


  • I made the following change in a local copy of the library to get me past the problem.
    if (data.length > 3) {
    byte[] i2cData = new byte[data.length - 3];
    System.arraycopy(data, 3, i2cData, 0, data.length - 3);

    for (ModuleCallbacks it : callbacks) {
    ((Callbacks) it).receivedI2CData(data[2], i2cData);
    }
    }
  • I just got a different error.

    07-12 22:03:43.863    5043-5043/com.mbientlab.metawear.app E/AndroidRuntime﹕ FATAL EXCEPTION: main
        Process: com.mbientlab.metawear.app, PID: 5043
        java.lang.RuntimeException: Error receiving broadcast Intent { act=com.mbientlab.com.metawear.api.MetaWearBleService.Action.NOTIFICATION_RECEIVED flg=0x10 (has extras) } in com.mbientlab.metawear.api.MetaWearBleService$2@41c00190
                at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:788)
                at android.os.Handler.handleCallback(Handler.java:733)
                at android.os.Handler.dispatchMessage(Handler.java:95)
                at android.os.Looper.loop(Looper.java:137)
                at android.app.ActivityThread.main(ActivityThread.java:5082)
                at java.lang.reflect.Method.invokeNative(Native Method)
                at java.lang.reflect.Method.invoke(Method.java:515)
                at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:782)
                at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:598)
                at dalvik.system.NativeStart.main(Native Method)
         Caused by: java.lang.NullPointerException
                at com.mbientlab.metawear.api.MetaWearBleService.execGattAction(MetaWearBleService.java:397)
                at com.mbientlab.metawear.api.MetaWearBleService.queueCommand(MetaWearBleService.java:2401)
                at com.mbientlab.metawear.api.MetaWearBleService.queueRegisterAction(MetaWearBleService.java:2368)
                at com.mbientlab.metawear.api.MetaWearBleService.queueRegisterAction(MetaWearBleService.java:2332)
                at com.mbientlab.metawear.api.MetaWearBleService.access$1600(MetaWearBleService.java:80)
                at com.mbientlab.metawear.api.MetaWearBleService$MetaWearControllerImpl$11.readDigitalInput(MetaWearBleService.java:1636)
                at com.lethala.blink.MainActivity$1$1.receivedI2CData(MainActivity.java:195)
                at com.mbientlab.metawear.api.controller.I2C$Register$1.notifyCallbacks(I2C.java:62)
                at com.mbientlab.metawear.api.MetaWearBleService$2.onReceive(MetaWearBleService.java:343)
                at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:778)
                at android.os.Handler.handleCallback(Handler.java:733)
                at android.os.Handler.dispatchMessage(Handler.java:95)
                at android.os.Looper.loop(Looper.java:137)
                at android.app.ActivityThread.main(ActivityThread.java:5082)
                at java.lang.reflect.Method.invokeNative(Native Method)
                at java.lang.reflect.Method.invoke(Method.java:515)
                at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:782)
                at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:598)
                at dalvik.system.NativeStart.main(Native Method)
  • Are you by chance periodically scheduling readRssi (or readBatteryLevel) function calls?
  • "Are you by chance periodically scheduling readRssi (or readBatteryLevel) function calls?"

    No. I currently call those once each in the connected() callback method.
  • edited July 2015
    Since you are have the source in hand, you can try replacing the single line while loop causing the error (https://github.com/mbientlab/Metawear-AndroidAPI/blob/1.8.0/app/src/main/java/com/mbientlab/metawear/api/MetaWearBleService.java#L397)

    with this expanded version:

    while(!actions.isEmpty()) {
        Action next= actions.poll();
        if (next != null) {
            lastResult= next.execute();
        }
    }
  • Thanks. I'll give that a try.
This discussion has been closed.