Weird crash at Math.floor

Hi, I have one Math.floor that is crashing when the watchface is downloaded from store but works as expected when side loading to device or simulator. The value i'm rounding is declared as Double and i'm checking for null and provide a default value, still crashing. The value comes from the properties. I even displayed the value in a text and i can see it on the screen while it's freezed before it crashes.

ERA says: Error Name: Invalid Value

From tests only with null i could get this error. Does anyone have a clue what might be wrong?

function recalculate(dc, a as Double, b as Double) {

if (a == null) {
a = 9.0;
}
var s = a+","+b;
dc.setColor(Gfx.COLOR_DK_GREEN, Gfx.COLOR_TRANSPARENT);
dc.drawText(120, 120, Gfx.FONT_TINY, s, Gfx.TEXT_JUSTIFY_CENTER);

var h1 = Math.floor(a);
Edit: I commented the code and now crashes at next line which is 'a' multiplied with a constant, but the error is different: Error Name: Unhandled Exception. There's nothing really in the stack something that could give exceptions.
  • Seems that the problem was the type, it was something else but not a Double, so i converted it with toDouble after getting from Properties. Getting Numbers seems to work just fine without any conversion, but Double doesn't work.

  • It's always a good idea to check for what you expect to get when reading settings,

    See https://forums.garmin.com/developer/connect-iq/w/wiki/4/new-developer-faq#settings-crash

    I have a variation of that in all my apps.

  • Not related to this but the saga continues. My data fields are in modules and i have an inexplicable crash when accessing the heartrate module at the line of it's definition. There were only 3 crashes, probably from the same user.

    Error Name: Invalid Value
    Occurrences: 1
    First Occurrence: 2022-03-14
    Last Occurrence: 2022-03-14
    Devices:
        fēnix® 7: 7.24
    App Versions: 1.3.0
    Languages: jpn
    Backtrace:
        hr.<init>:3

    using Toybox.SensorHistory;
    
    module hr {
    
        function getValue() as String {
    
            var value = "--";
    
    		var sensorIter = getIterator();
    		if (sensorIter != null) {
                var data = sensorIter.next().data;
                if (data != null) {
                    value = data.toNumber().toString();
                }
            }
    
            return value;
        }
        .......

  • 1. settings and float/double - it's a problem with them. So use strings in settings and convert to it. An remember no international chars 1.243 instad of 1'346,67

    2.  <init> ...

    I have this a few times. The problem was difficult to solve I've discover e.g. (but not every time probably initialising order has meaning)

    class...

    {

        const c_const =12;

       var mC = c_const ;

    }

    so try to avoid it and initialise mC in function.