Complete
over 1 year ago

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 Comment Children
  • This is a simulator bug. If I exit the app in the simulator before trying a new run instance ( Run-> Start Debugging on same device) then everything works. If I exit the simulator (quit) before another debug run then everything works. If I "Start Debugging" while one is currently running then crashes every time with same message and no stack trace. After a series of crashes in the app I'm running then on close of the simulator I get the apple crash window.

  • to clarify. It never crashes on the first run of the simulator

  • 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 );
    			}
    }
    

  • It crashes without ever accessing self.heartBeatIntervals.