Unhandled exception drawText on Edge 540/840 with firmware 20.x

I have a bunch of data fields running on most if not all Edge devices since a few years now.

A week ago or so I started to get many user reports of my data fields crashing on Edge 540/840 since firmware 20.x started to roll out. I have a 540 myself and I was able to confirm that after upgrading the firmware to version 20.19 I started to have the same problem.
The same data fields code remain unchanged since July 2023, and they worked fine up to firmware 19.22 on the same devices.

In ERA I don't see any other affected devices than 540/840 with 20.x firmware.

Running the same code in the simulator works just fine, so I suspect this is a firmware specific bug rather than an application code issue.
According to ERA crash reports the line of code that is causing the unhandled exception is the following:


dc.drawText(123, 12, Gfx.FONT_MEDIUM, Ui.loadResource(Rez.Strings.label), textCenter);

For the sake of completeness I'm adding a larger code snip:

using Toybox.Graphics as Gfx;
using Toybox.WatchUi as Ui;
hidden var textCenter = Gfx.TEXT_JUSTIFY_CENTER | Gfx.TEXT_JUSTIFY_VCENTER;

dc.drawText(123, 12, Gfx.FONT_MEDIUM, Ui.loadResource(Rez.Strings.label), textCenter);

The ERA/app crash logs generated are very limited in actionable data, only providing the error type (unhandled exception in this case) and the line(s) of code involved, but no other details on what exactly is causing the exception.

I checked the firmware release notes and I couldn't find any documented change that can be causing this.

Any ideas?

  • 1. try to see if changing the parameters helps. Maybe only FONT_MEDIUM has the problem? What's in the string? Is it ASCII? (Though IMHO even if not then it shouldn't crash, just display boxes). Is the string multi-line? Is it longer than what can be displayed?

    2. report the bug: https://forums.garmin.com/developer/connect-iq/i/bug-reports

  • String is ascii, yes. Just letters and a plus sign.
    Is not multi-line and 8 chars max.

    Will try to play with the parameters, I’m also wondering if the loadResource maybe be involved so will try to replace it with just a string.

  • Good idea, forgot to tell that it's worth to move the loadResource to a previous line, maybe that has the problem and not drawText.

  • I did that and the problem remains, but it seems the "pc" numbers changed in the CIQ_LOG.YML file.

    Yet there is something that is also confusing me. If I convert the pc value in the log file from hex to decimal and then search for it in the debug.xml file included in the release package, I can't find it. Not sure what I'm missing here.

  • Look at the *debug,xml file in the same folder where your "build for device" file is, or build a debug version in "build for device" and you'll see a friendly stack trace..  The debug files is the iq file are only for the prg files in that iq file

  • I was looking at the log for a build from the app store. This is why I assumed that if I use the debug.xml from the iq file I should find the pc’s.

    Anyway, I will build a debug version and see where it takes me.

    BTW I’m still using Eclipse, I don’t use VS Code and didn’t have time to install it yet. Would that have anything to do?

    Another thing I noticed is that back in July I built the data fields using SDK 4.2.2 and there was no problem but last night I had to update at least to SDK 4.2.4 or otherwise at build time I would get an error regarding Edge 540 requiring a minimum version of SDK 4.2.4. In any case I updated to the latest version but I found odd that at some point Garmin decided to change the minimum version of the SDK for the same device. At least it never happened to me since 2017 that I’m working with this.

  • Found the cause of the problem. For some reason after the firmware update on Edge 540/840, the API version was bumped to 5 (it was 4 before).

    This is very weird because in this article: https://developer.garmin.com/connect-iq/compatible-devices/
    API level is still documented as 4.2.0.
    Also the simulator is still reporting API version 4 on SDK 6.4.2.

    Because of the API version change, it broke my code since I'm using that to differentiate the Edge 540/840 from the Edge 530/830.

    Anyways, I will now update my code to account for this change and upload new versions of the data fields.

    Thanks everyone for your replies

  • What's your code to differentiate between them?

  • This is it:

    var apiver = Lang.format("$1$", Sys.getDeviceSettings().monkeyVersion);

  •  A number of devices have beta FW with CIQ 5, like the Fenix7, Epix2, fr165,255.955.265.965, va5 Venu3.

    You don't see this in the sim as it's beta FW