GlanceMode causing Error: Illegal Access (Out of Bounds)

I'm writing a widget. The widget shows the results of some web API calls.

The widget is working well on fenix 5 in the simulator and on fenix 6 with glance mode turned off.

When I enable glance mode, my app initialize gets called and completes, and then I get a fatal error:

Error: Illegal Access (Out of Bounds)
Details: Failed invoking <symbol>
Stack:
- onWebData() at /Users/x/dev/garmin/api-track/source/WebApi.mc:78 0x100017fe

The line of code the stack errors on is just the last line of code in that file and doesn't seem to be relevant.

Can anyone suggest likely mistakes I should look for, or how I debug the issue further?

Thanks

  • Are you doing something on onStop that's not annotated with (:glance)?

    Show the code around like 78 in that file - what function is it in?

  • OK, found it.

    Of course, I'd spent a long time before posting and then found it quickly after posting...

    The issue here was a call to Rez.Drawables done as part of a class var — i.e.

    class Foo {
      var bar = Rez.Drawables.baz;

      function initialize() {
        ...
      }
    }

    Because Rez.Drawables.baz is not scoped for glance this throws the Out of Bounds error.

    Would be nice if the stack reference matched up to the error (it was a long way away).

  • I have noticed some strange errors when glance code calls something which is not annotated for inclusion in a glance. This is typically the first thing I check for now when getting weird errors like this.