Complete

Array out of bounds error in trivial heartBeatIntervalsCallback()

Trying to troubleshoot a crash in on Venu 3, I found that the simulator (SDK 6.4.2) also gives a crash for a trivial  heartBeatIntervalsCallback()

   function initialize() {
        View.initialize();
        Sensor.setEnabledSensors([Sensor.SENSOR_HEARTRATE]);
        Sensor.enableSensorEvents(null);
    }
 
  var heartBeatIntervals as Lang.Array<Lang.Number> = [] ;

    function heartBeatIntervalsCallback(sensorData as Toybox.Sensor.SensorData) as Void {
        if (sensorData has :heartRateData){
            if (sensorData.heartRateData != null) {
                heartBeatIntervals = sensorData.heartRateData.heartBeatIntervals;
            }
        }
    }

From the debug console:

Error: Array Out Of Bounds Error Details: Error in sensor data callback Stack:
Encountered app crash.
---------------------------------------------------------------
Sometimes this takes a few minutes to happen.  This is in an activity app.
Parents
  • I have this same error in the latest simulator. It is random ie you can run the simulator several times and sometimes it crashes and sometimes it doesn't.  SDK7.2.1. Seems to occur on smaller/older devices.

    Note it doesn't occur if I start up the sensors before the data stream is started (simulation->activity data->start)

    It only occurs if you start the app run it for a few seconds then start another run of the app. ie the data stream is active providing HR intervals

    My code checks for nulls and zero size data.

    If I remove any use of the data it still crashes ie contents of for loop

    if (sensorData has :heartRateData && sensorData.heartRateData != null) {
    			heartBeatIntervals = sensorData.heartRateData.heartBeatIntervals;
    			
    			...code for status updates
    			
    			if (heartBeatIntervals == null) { 
    				return;
    			}
    
    			for ( var i=0; i< heartBeatIntervals.size(); i++) {
    				var intMs = heartBeatIntervals[i];
    				$.mSampleProc.rawSampleProcessing(isTesting, mHRDataLnk.livePulse, intMs, 1 );
    			}
    }
    

Comment
  • I have this same error in the latest simulator. It is random ie you can run the simulator several times and sometimes it crashes and sometimes it doesn't.  SDK7.2.1. Seems to occur on smaller/older devices.

    Note it doesn't occur if I start up the sensors before the data stream is started (simulation->activity data->start)

    It only occurs if you start the app run it for a few seconds then start another run of the app. ie the data stream is active providing HR intervals

    My code checks for nulls and zero size data.

    If I remove any use of the data it still crashes ie contents of for loop

    if (sensorData has :heartRateData && sensorData.heartRateData != null) {
    			heartBeatIntervals = sensorData.heartRateData.heartBeatIntervals;
    			
    			...code for status updates
    			
    			if (heartBeatIntervals == null) { 
    				return;
    			}
    
    			for ( var i=0; i< heartBeatIntervals.size(); i++) {
    				var intMs = heartBeatIntervals[i];
    				$.mSampleProc.rawSampleProcessing(isTesting, mHRDataLnk.livePulse, intMs, 1 );
    			}
    }
    

Children