Ticket Created
over 3 years ago

WERETECH - 10116

Code crash only when type = widget

Hi,

I copied a code base for an app in eclipse using latest compiler. 

I made a few changes to the code... adding glance view, annotating widget view, updated the xml to type = widget...

When I run it as a widget it crashes in the widget initialise function. If I keep commenting out lines the failure moves down the function code. The error is not very helpful

Error: Illegal Access (Out of Bounds)
Details: Failed invoking <symbol>
Stack:
- initialize() at HRVWidget.mc:228 0x100005e7

If I now set the manifest type to "App" the code runs fine. So no code changes!

Any ideas welcome as beating head against a brick wall on this one.

Regards,

David

  • Many thanks Travis. I hadn't appreciated that I needed to bring everything on the code path for a glance into "scope". I had assumed that annotating things with :glance was an exclusive function ie they would only appear in the glance scope and not in the app/widget as well. (Sorry if the terminology is wrong).

    To maybe say it another way: all functions and resources are in scope of the app/widget but only those annotated with :glance are in scope of the glance itself. In addition the code needs to be annotated such that the widget or glance functions and resources during each lifecycle are available as they essential overlay each other.

    I solved it by refactoring the code but now I understand this I may revert and annotate it correctly.

    Regards,

    David

  • -

    All code or resources that are called or referenced while loading the glance view needs to be made available to the glance or it needs to be removed from the code path that is invoked when loading the app and the glance view.

    Consider the following snippet...

    class HRVApp extends Application.AppBase {
    
        function initialize() {
            AppBase.initialize();
    
            doSomethingOnAppInit();
            
            var resourceString = Application.loadResource(Rez.Strings.HRVString);
        }
        
        function onStart(params) {
            doSomethingOnStartup();
        }
        
        function onStop(params) {
            doSomethingOnShutdown();
        }
        
        (:glance) function getGlanceView() {
            doSomethingOnGlance();
            $.aGlobalAccessedInGlanceCode = 1;
    
            return [ new HRVGlanceView() ]
        }
        
        function getInitialView() {
            doSomethingOnView();
            $.aGlobalNotAccessedInGlanceCode = 2;
    
            return [ new HRVView(), new HRVViewDelegate() ];
        }
    }

    The following functions are called as part of the application life cycle...

    1. HRVApp.initialize()
    2. HRVApp.onStart()
    3. The appropriate view/delegate:
      1. HRVApp.getServiceDelegate() when running in the background
      2. HRVApp.getGlanceView() when running as a glance
      3. HRVApp.getInitialView() when running as a widget/app
    4. HRVApp.onStart()

    If you are annotating code with :glance, then the following functions and resources would need to be annotated as such:

    1. doSomethingOnAppInit()
    2. Rez.Strings.HRVString
    3. doSomethingOnStartup()
    4. doSomethingOnGlance()
    5. $.aGlobalAccessedInGlanceCode
    6. doSomethingOnShutdown()

    My guess is that your app isn't annotating everything that is referenced when loading the glance view.

  • It appears that the "state" and capabilities available on initialise() and onstart() are different between apps and widgets. For instance I know I can't initialise a sensor in onstart() for a widget but can in an app. Is this documented anywhere? 

  • Ok. Dug into this some more over the last few days.

    I annotated the functions in the widget class definition to make them essential have no content.

    In the initialize function I commented out every line and then added them back in. It obviously worked when all were commented out. What appears to be the case is that in a widget I can NOT load any resource or create new instances of any class eg mStorage line above. With all the calls in Initialize commented out the code then fails in the initialView code on a call to a global debug buffer flush ie $.flushMsg(); . Removing this then allows the initial view to be displayed and the delegate behaviour first level menu to be displayed.

    With all the initialise lines commented out besides $._mApp = ... then this assignment now works. It appears any local variable access/assignment and Monkey C library calls work but nothing defined by my code in other classes.

  • Hi Jim,

    I deleted all of the FIT related code :-)

    function initialize() {
    Sys.println("HRVWidget INITIALISATION called");

    AppBase.initialize();

    $._mApp = Application.getApp();

    // Retrieve device type
    mDeviceType = Ui.loadResource(Rez.Strings.Device).toNumber();

    mStorage = new HRVStorageHandler();
    // ensure we have all parameters setup before needed
    mStorage.readProperties();

    etc

    fails at $._mApp, comment this then fails at next line etc. Putting a return in causes a crash in another function