Datafield crashes after configuring using Garmin Express, but not using GCM

Recently the user of one of my datafields has  reported a crash that happens when the datafield is used after configuring using Garmin Express.

The datafield allows configuration of 2 properties and uses some other properties that are not configurable by the user.

I have been able to reproduce the failure on an Edge 1030 running firmware 9.00 and 9.02 (as the user) and Garmin Express 6.19.1 (mac). Crash happens only if I configure the datafield. According to crash report obtained from ERA tool, crash happens when I try to use a variable that I have initialized with the value of one of the properties NOT configured in Garmin Express.

However, if I work on the simulator, datafield works fine even if I perform same configuration using App Settings Editor.

Same way, if I configure the datafield using Garmin Connect Mobile, it also works with no crash.

I don't know if I may have included any bug that is only affected by the way in which Express is storing values for properties and not by GCM or the App Settings Editor (if there is any difference).

I would appreciate any advise to fix this issue.

  • See the New Developer FAQ wiki about settings and the wrapper function for checking types.

  • Thanks jim_m_58. I have read the FAQ and implemented following wrapper function. However I see same results. No issue when I configure using GCM, but the datafield crashes after doing it in Garmin Express.

    According to ERA tool, there is an Unhandled Exception when I try to get property value

    function getCheckedProperty(propertyName, defaultValue) {

    var value = App.Properties.getValue(propertyName);

    if (value == null || !(value instanceof Number)) {

    if (value != null) { value = value.toNumber(); }

    else { value = defaultValue; }

    }

    return value;

    }

  •  What is it pointing to in your code?  If it's in something like an "if" block, what's in that block?

    You could put a try/catch around that line and get the text for the exception.

  • I doubt this is causing any problem in your case, but one thing to note with that wrapper function is that toNumber() does not exist for Booleans - so I add a check for "instanceof Boolean" and treat that the same as null just to be safe in all possible cases.

  • I noticed that, so to prevent any issue with booleans, I modified the code using only number properties. 

  • I have modified wrapper function to use Application.getApp().getProperty() instead of App.Properties.getValue() to avoid exception when property is not defined in settings that happens according to API doc.

    function getCheckedProperty(propertyName, defaultValue) {
        var value = Application.getApp().getProperty(propertyName);
    	if (value == null) {
    		value = defaultValue;
    	}
    		
    	if (!(value instanceof Number) and !(value instanceof Boolean)) {
    		value = value.toNumber();
    	}
    	return value;
    }

    After that, getProperty() returns null for properties not involved in settings. But it only happens after configuring the datafield by using Garmin Express. Not if I don not configure it, neither if I configure using GCM. In fact, current implementation avoids crash, so the data field continues running without correct values for that properties after Express config, and if I configure it again using GCM when the datafield is active, property values are correctly returned

    I try to get value of the properties from onUpdate()

     As there are some differences in the way I define properties that are set by user (good value is returned for them) and properties that I use to define values in the code depending on the layout (null after Express config), I provide the file structure I am using.

    • resources/properties/properties.xml: defines two properties that are set by user
    • resources-rectangle-###x###/properties/layout.xml: defines several tens of properties I use to obtain values depending on the device screen and datafield size

    Maybe I am doing something wrong using this structure.

  • I never use properties without an associated setting.  Also, when you reach about 100 properties, things can go odd, even if they have a setting.  For what you're trying top do, have you considered another option such as a specific .mc with your constants, when one is included in the build using jungles?

  • Thanks for this advise. I have updated the code to avoid using properties. Now using jungles and mc files for defining required variables, it works.

    In addition, communication between device and GCM that was working randomly when I tried to configure the datafield using GCM ( discussed in this topic link) is now robust.