asynchronous processes and variables and errors

Lets see example

var global gV;

function classA_setThemeParams(colour)

{

  gV= col;

  ....

}

function onLayout(dc)

{

classA_setThemeParams();

}

function onUpdate(dc)

{

for(i...)

{

    //something external fe. backgroung call classA_setThemeParams during the loop

    drawables(i).draw(dc);//samewher in drawables there is dc.setColor(gV,gV);  <----------------------------------- from time to time error, why?

}

Error Name: Symbol Not Found Error

Error Name: Invalid Value

Why this happen?

gV should be handle an point to  value

this example  show that

- sdk makes "local var" from global instead of taking value from def every time

- during operation = sdk change handle to object

  • User code in the ConnectIQ virtual machine is single threaded. There should be no concurrency issue.

    The onBackgroundData function is called in the foreground context only. you should be able to store that data in application storage for later use if you wish (you should prefer Application.Storage module if it is available. It is more robust and the AppBase Property APIs are not going to be available on new devices).

    After reading your post, it sounds like you are seeing issues where you call setProperty in onBackgroundData (once to free the old value and again to store the new one) and then you are reading back something different in onUpdate?

  • I use 2.3.x and storage is from 2.4 and not sure if for wf.

    yes, setProperty twice first with null (to prevent peak memory because I get out of memory error) than data. Than onUpdate but exactly on one of drawable which is draw every minutes but

    - when start app data is read in "first" onUpdate because I check actual minutes to members minutes which are null

    - later when clock's minutes change

    because background run in background reading can be done from 1 to 59 second after onBackgroundData i dont know when, now from refactoring there is silent but you know it wasn't persistent error now is:

    //app
    function onBackgroundData(d)
    {
        ...
        if (((d[GPS_LAT] != null) && (d[GPS_LON] != null)) 
    	{
    	    d[GPS_valid] = true;
    	    setProperty("k", null);
    		setProperty("k", d);
    		mW = true;//<-- member APP
    	}
    	...
    }
    //view
    function onUpdate(dc) 
    {
        ...
        NowFLD.draw(dc);
        ...
    }
    
    function onBD(dc) 
    {
        ...
       d = APP.getApp().getProperty("k");
       if((d != null) && (d[GPS_valid] != null) && d[GPS_valid])
       {
            lat = d[GPS_LAT];//<---- null, impossible, 
       }
        ...
    }
    
    
    //NowFLD
    function draw(dc)
    {
        ...
        if(mM != gCT.min)
        {
    		mM = gCT.min;
    						
    		x = APP.getApp();
    		X = x.mV;       //mV=view
    		
    		if(x.mW)
    		{
    			x.mW = false;
    			X.onBD();//<---------------------
    			..
    		}
        ...
    }
    

    of course I have to make order and move onBD to NowFLD but I'm waiting an observe because Era clears log after update version

  • Speaking of refactoring and saving memory, you can refactor

    if((d != null) && (d[GPS_valid] != null) && d[GPS_valid])

    to

    if((d != null) && (d[GPS_valid] == true))

    ^ this works even if d[GPS_valid] is null.

    If you're sure that d[GPS_valid] can never be null, this can be further simplified to
    if((d != null) && d[GPS_valid])

    Unfortunately (as you probably noticed), there's a long-standing CIQ bug/quirk where if (x && y) will crash if y is null (whereas if (y) works just fine in the same scenario). In other words, null is only sometimes implicitly converted to boolean.

  • yes, I noticed this bug, I had to test many situation:

    //    var x = null, a = true;
    //    
    //    if(a && x)<----------------- error
    //    {
    //        print("obtXV", "true");
    //    }else
    //    {
    //        print("obtXV", "false");
    //    }

    //    var x = null, a = 12;
    //    
    //    if(a != x)
    //    {
    //        print("obtXV", "rózne");//<-----------------------------
    //    }else
    //    {
    //        print("obtXV", "równe");
    //    }
    //    var x = null;
    //    
    //    if(x)
    //    {
    //        print("obtXV", "if(null)-true");
    //    }else
    //    {
    //        print("obtXV", "if(null)-false");//<-----------------------------
    //    }

    Slight smile

    in many situation I have to do a lot strange checking because

    - unfortunately there is a lot of bug in SDK device,

    - bigger problem is that that bug aren't corrected quickly

    - I'm not sure system e.g. something should not be null but is

    really hard work

  • Yes, I discovered many bugs when I first started developing CIQ apps, as I would relentless refactor and minimize code to save memory, including the if (x && y) crash when x or y is null.

    I will say that Garmin is usually pretty good at responding to bug reports, and a lot of the bugs actually do get fixed, but sometimes only on the newer devices. If I'm not mistaken, the if (x && y) bug may have been considered a "design decision" and not a bug, so it may not have been fixed.

    So if you find issues and you can reproduce them with a simple test case, it's definitely worth reporting them in the bug report forum.

  • I have first error Disappointed exactly in place I've described.

    But the ERA shows line that isn't 100% good and I didn't modify source code.  Should I prepare code for ERA in any special way?

    let's see

    Error Name: Invalid Value
    Occurrences: 1
    First Occurrence: 2021-02-18
    Last Occurrence: 2021-02-18
    Devices:
        fÄ“nix® 6S Pro / 6S Sapphire / 6S Pro Solar / 6S Pro Dual Power: 13.10
    App Versions: 1.7.2
    Languages: deu

    Backtrace:
        PSX1_Vie.onBD:1007                         here is an error in line after getProperty checking first if "head" of data are valid
        PSX1_NowField.draw:129                   can call Vie.onBD OK
        PSX1_Vie.onPartialUpdate:2096         possible can call NowField.draw but not directly first call viev.draw
        PSX1_Vie.onExitSleep:2226                impossible: no any function call and if exitSleep no onPartial

  • Where are GPS_LAT, GPS_LON and GPS_valid defined? I assume they're all strings....

  • before setProperty in onBackgroundData

    no, no string Slight smile, array of float

    but now is problem that ERA shows bad line numbers it happened early when onBackgroundData called view.onBD and it looked like in the same time was calling the same function one from onUpdate second from app.view.

    but now in onBackroundData I only set app.mW to true and data waits as I describe in code example and then minutes change in PSX1_NowField.draw check app.mW and if it's true call view.onBD,

    ok, I move onBD from view to PSX1_NowField maybe problem is when view call PSX1_NowField and PSX1_NowField call view.onBD

    recompile and I'll wait

    I'll think and maybe problem is not in flow but in getProperty because

    Error Name: Invalid Value

    according  to ERA error is in if(dic[lat]< 0.0) first was checked  dic !=null and even check dic[lat] !=null

    I expected float maybe it return for example string or something unknown, I've read for new developer that there was a bug but in sim shows good types but I write only getIntProp

  • previous was on 

    Error Name: System Error
    Occurrences: 1
    First Occurrence: 2021-02-16
    Last Occurrence: 2021-02-16
    Devices:
        fÄ“nix® 6 Pro / 6 Sapphire / 6 Pro Solar / 6 Pro Dual Power / quatix® 6: 13.10
    App Versions: 1.6.1
    Languages: ita
    Backtrace:
        PSX1_Vie.onBD:878

    in another place but also checking float

    Italian version and now German

    I have got fenix 6 pro and Polish (comma decimal separator) and no problem but I have FW 15.20 beta. And I mentioned about float problem in settings but I've changed settings to string an convert it to float now. Maybe I should the same reading data?

  • previous was on 

    Error Name: System Error
    Occurrences: 1
    First Occurrence: 2021-02-16
    Last Occurrence: 2021-02-16
    Devices:
        fÄ“nix® 6 Pro / 6 Sapphire / 6 Pro Solar / 6 Pro Dual Power / quatix® 6: 13.10
    App Versions: 1.6.1
    Languages: ita
    Backtrace:
        PSX1_Vie.onBD:878

    in another place but also checking float

    Italian version and now German

    I have got fenix 6 pro and Polish (comma decimal separator) and no problem but I have FW 15.20 beta. And I mentioned about float problem in settings but I've changed settings to string an convert it to float now. Maybe I should the same reading data?