Skip to content

App crash: Insulin momentum and prediction values can be calculated to become NaN #351

Closed

Description

@tmecklem

In the work for PR #349, I've noticed that it's possible for insulin momentum and prediction values to be calculated so that isNaN is true. It seems to be whenever there is a gap in the sensor data due to an error such as a SensorWeakSignal. I don't know enough to track this down to a root cause, but I have several stack traces that I will add in subsequent comments. I have not seen this particular error when using a G5 sensor, so at this point I'm assuming it's something that the x22 enlite code is doing that is causing the unexpected calculations.

Activity

  1. tmecklem commented on Dec 31, 2016

    @tmecklem
    Author

    Crash in DiagnosticLogger.addLoopStatus

    Fatal Exception: NSInvalidArgumentException
    Invalid number value (NaN) in JSON write
    
    ...
    22 Foundation                     0x1916b4cc0 +[NSJSONSerialization dataWithJSONObject:options:error:]
    23 Loop                           0x100156fa8 specialized DiagnosticLogger.addMessage([String : Any], toCollection : String) -> () (DiagnosticLogger.swift:31)
    24 Loop                           0x1000be9fc DiagnosticLogger.addLoopStatus(startDate : Date, endDate : Date, glucose : GlucoseValue, effects : [String : [GlucoseEffect]], error : Error?, prediction : [GlucoseValue], predictionWithRetrospectiveEffect : Double, recommendedTempBasal : (recommendedDate : Date, rate : Double, duration : Double)?) -> () (DiagnosticLogger+LoopKit.swift)
    25 Loop                           0x1000dd604 specialized LoopDataManager.(updatePredictedGlucoseAndRecommendedBasal() throws -> ()).($defer #1)() -> () (LoopDataManager.swift)
    26 Loop                           0x1000daab4 LoopDataManager.updatePredictedGlucoseAndRecommendedBasal() throws -> () (LoopDataManager.swift)
    27 Loop                           0x1000d865c LoopDataManager.update() throws -> () (LoopDataManager.swift:217)
    28 Loop                           0x1000de57c specialized LoopDataManager.(getLoopStatus(([GlucoseValue]?, [GlucoseValue]?, (recommendedDate : Date, rate : Double, duration : Double)?, DoseEntry?, Date?, InsulinValue?, CarbValue?, Error?) -> ()) -> ()).(closure #1) (LoopDataManager.swift:258)
    29 Loop                           0x1000dac9c LoopDataManager.(getLoopStatus(([GlucoseValue]?, [GlucoseValue]?, (recommendedDate : Date, rate : Double, duration : Double)?, DoseEntry?, Date?, InsulinValue?, CarbValue?, Error?) -> ()) -> ()).(closure #1) (LoopDataManager.swift)
    30 libdispatch.dylib              0x18f9a21fc _dispatch_call_block_and_release
    ...
    
  2. tmecklem commented on Dec 31, 2016

    @tmecklem
    Author

    Crash in StatusChartManager

    fatal error: Invalid range generating axis values: file /Users/pete/dev/Loop/Carthage/Checkouts/SwiftCharts/SwiftCharts/Axis/ChartAxisValuesGenerator.swift, line 99
    
    ...
    3  SwiftCharts                    0x1008cedc8 _TZFV11SwiftCharts24ChartAxisValuesGenerator34generateYAxisValuesWithChartPointsfTGSaCS_10ChartPoint_15minSegmentCountSd15maxSegmentCountSd8multipleSd18axisValueGeneratorFSdCS_14ChartAxisValue23addPaddingSegmentIfEdgeSb_GSaS2__ + 32
    4  Loop                           0x100068c38 StatusChartsManager.generateGlucoseChartWithFrame(CGRect) -> Chart? (StatusChartManager.swift:363)
    5  Loop                           0x100071788 _TTSf4n_n_g__TFC4Loop19StatusChartsManager21glucoseChartWithFramefVSC6CGRectGSqC11SwiftCharts5Chart_ (StatusChartManager.swift:338)
    6  Loop                           0x10004562c specialized StatusTableViewController.(tableView(UITableView, cellForRowAt : IndexPath) -> UITableViewCell).(closure #1) + 4295644716
    7  Loop                           0x10003fde4 StatusTableViewController.(tableView(UITableView, cellForRowAt : IndexPath) -> UITableViewCell).(closure #1) + 4295622116
    8  Loop                           0x1000869e0 thunk (PredictionTableViewController.swift)
    9  Loop                           0x100025fe8 ChartContentView.layoutSubviews() -> () (ChartContentView.swift:17)
    10 Loop                           0x1000260d4 @objc ChartContentView.layoutSubviews() -> () (ChartContentView.swift)
    11 UIKit                          0x1969cba80 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 1196
    ...
    
  3. loudnate commented on Dec 31, 2016

    @loudnate
    Collaborator

    It seems to be whenever there is a gap in the sensor data due to an error such as a SensorWeakSignal.

    It sounds like you might be sending invalid or repeat glucose entries into GlucoseStore.

  4. tmecklem commented on Dec 31, 2016

    @tmecklem
    Author

    That sounds like a good place to look next. I'll take a look and report findings back here. Would momentum calculations be thrown off if there are duplicate entries of the same value for the same time?

  5. loudnate commented on Dec 31, 2016

    @loudnate
    Collaborator

    Yes, that could result in a divide-by-zero when calculating slope. There isn't a valid reason to have duplicate entries, though, right?
    You're not using NaN as a sentinel anywhere, right?

  6. tmecklem commented on Dec 31, 2016

    @tmecklem
    Author

    Correct. Based on my current understanding, there's only valid sgv entries going in, but there may be duplicates that I'm not accounting for adequately.

  7. tmecklem commented on Dec 31, 2016

    @tmecklem
    Author

    I added a filter by date for the entries being added to the GlucoseStore to make sure that no duplicates are added, and the app did not crash during a sensor weak status like it did before the change. @loudnate thanks for pointing me in the right direction.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions