Symbol lookup best practices?

Most of the time the simulator starts without a problem, but sometimes I get this when I start:

Error: Invalid Value

Details: Failed invoking <symbol>
Stack:
- onUpdate() at C:\Users\Andy\Desktop\Garmin-GIT\Annulus\source\AnnulusView.mc:735 0x10002514

Encountered app crash.
Kill app for run the app
Failed to run the app: Timeout

What's worse it's happening on the watch, after a day or so onUpdate will stop updating when awake, but it does keep updating every minute awake or not. I get something similar in a CIQ_LOG file. I reselect the watch face and it's fine, at least for a while.

Can I fix this by helping the lookup process? I don't have any globals beyond Toybox, so do I use self to say it's a variable or function in the same class? Does a symbol need to be looked up everytime that piece of code is run, or does it remember after the first time? It seems like if it was remembering where it was it wouldn't break the next day.

  • It kind of sounds like you might be exceeding the power budget for onPartialUpdate.  When it gets in this state if you move to the widget/glance loop and back to the watch face, is it normal again for a minute or two?

  • 	//! Handle the partial update event
    	//! @param dc Device context
    	public function onPartialUpdate(dc as Dc) as Void {
    		_partially += 1;
    	}
    

    I hope not, I'm not using onPartialUpdate except as a counter so it has at least one line of executable code.

    Once it's reset, it's normal for hours. The code that causes the breakage is only executed in onUpdate when isAwake is true:

    	//! This method is called when the device exits sleep mode.
    	//! Set the isAwake flag to let onUpdate know it should render the second hand.
    	public function onExitSleep() as Void {
    		_isAwake = true;
    		_aWoken = true;
    	}
    

  • I might have found it. When the watch face reinitializes in the middle of the night (why is this happening) some variables get reset to zero, which could result in a divide by zero 700 lines later. I just biased one by a tiny bit and we'll see if that helps.

    For the original question, what about symbol name resolution? Any gains to made there?

  • I think it's a bug in the simulator. It happens to me as well once in a while and some other people wrote about it already in the forum as well.

  • What does mean reinitializes? Same values are reseted at midnight like steps and it's normal behaviour.

  • I mean that the initialize() function is run again, like the whole watch face code is restarted. I can tell because I see a println in the initialize function in the log file on the watch.

  • initialise app or view? 

  • but then what's the difference between the 1st time when you started the app. Those variables also started from 0. Why didn't it crash then? 

  • class myclass extends WatchUi.WatchFace;

    //! Initialize variables for this view
    public function initialize() {
    WatchFace.initialize();
    _screenShape = System.getDeviceSettings().screenShape;
    _partialUpdatesAllowed = WatchUi.WatchFace has :onPartialUpdate;
    _actInfo = Activity.getActivityInfo();
    _hasHR = _actInfo has :currentHeartRate;
    _locInfo = Position.getInfo();
    _hasPosition = _locInfo has :position;
    _sysStats = System.getSystemStats();
    _hasSolar = _sysStats has :solarIntensity;
    _profile = UserProfile.getProfile();

    and more code goes on from here.

  • I should add that I don't have anything in the AppBase part to see if it is being rerun, but it seems like it might be a good idea?