Random Array Out Of Bounds Error in sensor data callback

Former Member
Former Member
Hello,

i have an issue i am unable to debug...

I have implemented a b2b recorder that is part of an CIQ3 App i am working on.
In general my App works as i want it to but sometimes the App crashes randomly and i have no idea why.

Log and code follows...
  • Former Member
    Former Member over 6 years ago
    The log on my device says:


    Error: Array Out Of Bounds Error
    Details: Error in sensor data callback
    Time: 2018-11-02T07:02:00Z
    Part-Number: 006-B2888-00
    Firmware-Version: '4.00'
    Language-Code: deu
    ConnectIQ-Version: 3.0.4
    Filename: XXX
    Appname: XXX
    Stack:
  • Former Member
    Former Member over 6 years ago
    Stack is empty, so i have no idea where exactly the error is invoked.

    Only indicator for me is "Error in sensor data callback".

    Normally i expect "Array Out Of Bounds Error" for example when i have a for-loop trying to access an index of an array that is greater than the array size.
    But here i have no for-loops in my sensor data callback.


    Here the code in the callback:

    function onSensorData(sensorData){

    var BBI = sensorData.heartRateData.heartBeatIntervals;
    prosessBBI(BBI);

    }

  • Former Member
    Former Member over 6 years ago
    Furter i process my Array and check if it is empty for more than one time to indicate the user that likely the sensor is not sitting correct on the users wrist.


    hidden var hrvDataArray = new [0];


    function prosessBBI(BBIarray){


    if (BBI.size() == 0){
    validCounter++;
    }

    else {

    validCounter = 0;
    }

    if (validCounter > 1){

    hrvDataArray.add(-1);
    isValid = false;

    }

    else{

    hrvDataArray.addAll(BBI);
    isValid = true;

    }

    }



    Then i do some stuff with the hrvDataArray but that is not part of the sensor data callback or its subfunction.

    However, sometimes the App runs great for hours and sometimes it randomly crashes. But weather the console in the simulator nor the error log on the watch
    gives me information about where exactly to look for the bug.


    Do you have any idea what can be wrong there?


    Thanks a lot in advance.


    Mike
  • few things I'd look at since it's an out of bounds:
    1) you have

    if(BBI.size()==0) {

    but you're passing BBIarray, and BBI is local to onSensorData()

    2) if that's a typo, maybe do a null check

    if(BBIarray!=null) {
    If(BBIarray.size()==0) {

    3) for the addAll(), maybe include a check that what you're adding has a size>0
  • Former Member
    Former Member over 6 years ago
    but you're passing BBIarray, and BBI is local to onSensorData()

    [\quote]

    Yes that is a typo error. Initially all the code was in the onSensorData()...i just copied it in another function to explain the two different steps.

    I'll try the null checks and let you know if it works.


    Thank you!
  • Former Member
    Former Member over 6 years ago
    Ok, i did null checks and size checks and still, random crash!

    Same error message:

    Error: Array Out Of Bounds Error
    Details: Error in sensor data callback
    Time: 2018-11-02T12:21:42Z
    Part-Number: 006-B2888-00
    Firmware-Version: '4.00'
    Language-Code: deu
    ConnectIQ-Version: 3.0.4
    Filename: XXX
    Appname: XXX
    Stack:


    Any other ideas?

  • Maybe do a check that you are using an index into the array that's less than size? It might not be while you are building the array, but while you're using the array.
  • Former Member
    Former Member over 6 years ago
    I wrote the prosessBBI(BBIarray) function also in hope, that if it crashes the error log refers to this function instead of onSensorData.

    But still it error as shown above!


    In a next step i implicitly wrote an piece of code that invokes a Array Out Of Bounds Error inside my prosessBBI(BBIarray) to prove if then the "Stack" shows me where the error is located in the code.

  • Former Member
    Former Member over 6 years ago
    So i just defined ... se below ... the array will never be this size

    if (BBIarray != null){

    var x = BBIarray[100]; // here!!!

    if (BBIarray.size() == 0){

    validCounter++;

    }

    else {

    validCounter = 0;

    }

    if (validCounter > 1){

    hrvDataArray.add(-1);

    isValid = false;

    }

    else{

    if(BBIarray.size() > 0){

    hrvDataArray.addAll(BBIarray);

    isValid = true;

    }
    }
    }


  • Former Member
    Former Member over 6 years ago
    and i get:


    Error: Array Out Of Bounds Error
    Details: 'Failed invoking <symbol>'
    Time: 2018-11-02T12:42:11Z
    Part-Number: 006-B2888-00
    Firmware-Version: '4.00'
    Language-Code: deu
    ConnectIQ-Version: 3.0.4
    Filename: XXX
    Appname: XXX
    Stack:
    - pc: 0x100005db
    File: 'XXX'
    Line: 253 // here my wrong array is
    Function: prosessBBI
    - pc: 0x100006db
    File: 'XXX'
    Line: 297
    Function: onSensorData