Long story short, I ran into what seems like a bug or I'm missing something obvious (always possible). I'm not unfamiliar with coding although this is my first ConnectIQ foray. I'm writing a datafield to help me with my ultras (basically does a configurable long term rolling backwards pace average and projects forward with a finish time and remaining time and warnings on too fast/slow for target finish time) and had some problems. My datafield ran fine in the simulator but when I took it into the watch, Fenix 6x, it immediatly went ! on me. I started throwing in "I got to here" print lines and logging them out till I found where it was crashing and it was in the initialize.
TL/DR; trying to use a variable that pulls its value from a property in the property.xml that was a Float crashed the datafield on the watch but not in the simulator. And it's only for that one single Float that came in through configuring the datafield using the phone. I had to cast the value specifically as a float using .toFloat to get rid of the exception.
Longer story with more details -
In my config I have the following -
property.xml:
<property id="propTotalDistance" type="float">100.0</property>
settings.xml:
<setting propertyKey="@Properties.propTotalDistance" title="@Strings.settingTotalDistance">
<settingConfig type="Numeric" readonly="false"></settingConfig>
</setting>
pre-initialize:
hidden var propTotalDistance = App.getApp().getProperty("propTotalDistance"); //get target race distance from user config
hidden var totalDistance = 0.0; //preset with float
Initialize:
targetDistance = propTotalDistance * 1609.344; // covert to meters
And that initialize line threw an exception, trying to propTotalDistance in any calculation crashed the datafield on the watch. Through printing the values I confirmed that targetDistance = 0.00000 before I tried to set it which seems to indicate it's a valid Float. I was able to print propTotalDistance and get 100.00000 also indicating it seemed to be a float. This was confirmed in both the simulator through printing to log file on the watch. So setting a float to the result of multiplying a float with a float doesn't seem like it should cause a problem?
Yet when I tried to set targetDistance to propTotalDistance in any fashion, the datafield on the watch would crash. Ran just fine in the simulator.
The fix/workaround I eventually tried that worked was to change the offending line to this:
targetDistance = propTotalDistance.toFloat() * 1609.344; // covert to meters
And it worked fine. It's the only float I have in my settings for now so the workaround is okay if a bit goofy to me.
But is this a bug or am I doing something stupid? I don't have to do a .toFloat for any other number or equation and I have a lot of them, it's only when trying to use a Float that came in from the settings options is it crashing on the watch.