App crash question

Hi!

Somebody please explain to me how the following crash can happen:
ERROR: Unexpected Type Error
DETAILS: Failed invoking <symbol>
STORE_ID: 00000000000000000000000000000000
CALLSTACK:
D:\DEV\G\.\source\Messages.mc (handle:14)
D:\DEV\G\.\source\MainApp.mc (onBackgroundData:125)


Mainapp.mc:



Messages.mc

PROTOCOL_VERSION cannot be null since it has have been assigned in getInitialView.
data MUST BE a Toybox.Land.Dictionary since it was checked in Mainapp.mc:122

:confused:
  • Without seeing more, it looks like you're loading PROTOCOL_VERSION in the main process, but not in the background. (globals are not common between the foreground and background process). I'm not sure about loading resources in the background - I don't think I've tried.

    To pass something to the background, you can do it with the objects store/app settings, and the background can only read those but not set them.
  • Exactly. Everything you see here is in the main process. Nothing is in the background process. PROTOCOL_VERSION is set in the main process and also read in the main process.
  • Sorry, missed that. On a real device, onBackgroundData can be called before get InitialView(), If you try onStart() or initialize() for the AppBase, keep in mind that those are called for both the foreground and background
  • How is that possible? It is a watchface (not a watchapp), registerfortemporalevent is called in getInitialView() and deleteTemporalEvent() is called in onStop().
    That means the temporal event is only called if the watchface is visible (it is the main watchface) and that also means that onBackgroundData cannotbe called before getinitialView() since it is the getInitialiView() itself who registers the event.
  • It could be a timing thing as when the background is running, when you delete the temporal event, etc... If you WF crashed, the temporal Event probably won't get deleted so you could have data the next time.

    As a result of getting this crash would mean the temporal could still be running...

    Sys.println() calls can tell you a great deal on the watch.

    You're seeing this on a watch, correct, or just the sim?
  • It shouldn't be running. The deleteTemporalEvent() should stop the background event from running:
    https://developer.garmin.com/downloa...nstance_method
    This is what I'm doing in MainApp::App.AppBase onStop:
    function onStop(state)
    {
    //System.println(Lang.format("AppBase::onStop, is_background: $1$", [$.is_background]));
    if (!is_background)
    {
    Background.deleteTemporalEvent();
    }
    }


    unless I'm completly misunderstanding how the deleteTemporalEvent() works, when you start an activity, or even just a notification comes in, the onStop() should be called which stops the background event.
  • I updated my last post. If your app crashes, the background will likely continue to run.
  • Put in a bunch of println() calls and you can see how things happen on the watch, like maybe the background running when you don't expect it or something.
  • It could be a timing thing. That's the only explanation I can see now that happening. So that the PROTOCOL_VERSION is not initialized.

    Maybe I'll just give up on loading it from string resources and just declare them at the beginning of the mainapp.mc as literal strings, that should resolve this weird issue.

    We'll see.
  • The other thing you could do is stat PROTOCOL_VERSION as null, and then in onBackgroundData(), if it is null (getInitialView() hadn't been called yet), just toss it, as it's "old" data"