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 seems that the only way that this can happen, after seeing it again this morning, is that "_isAwake" is true, but the watch is in low power mode so onUpdate is only running once per minute. This is why the second hand is drawn at zero and then stays there until the next minute. For this to be the case, it means that the watch would have to have gone into low power mode without calling onEnterSleep to set _isAwake false.

    	//! This method is called when the device re-enters sleep mode.
    	//! Set the isAwake flag to let onUpdate know it should stop rendering the second hand.
    	public function onEnterSleep() as Void {
    		_isAwake = false;
    		WatchUi.requestUpdate();
    	}
    

    What are the conditions that allow the watch to go into low power mode and not call onEnterSleep? I looked for a way to see if the watch is in low power mode but the only one I could find is called "isSleepMode" and had been removed as of IQ 4. I don't know what the replacement, if there is one, is called.

  • I've solved the problem by doing this:

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

    Here's my submission for the kludge gallery. Grin

  • This is not correct solution for AMOLED devices 

    I have already written 'watch face can start in low power'.

    So check onLayout and onShow.

    Maybe there is a problem with requestUpdate() in onEnterSleep(), you can delete this line as system calls it itself.