Watchdog Tripped Error - Code Executed Too Long

Hello,

I need some advices. I have this problem with my app but no idea to solve it. My app allows to make a trail or hiking and it’s possible to display the current map. For that, I store in 2 arrays latitude and longitude (each 15 positions, it’s adjustable). When it’s requested by user during running/hiking, the map is displayed, each position in the arrays are displayed with the following code:

 

for(var i = iNbPosInArray-1; i > 0; i-- ) {

                         

             //segment N,N-1 centered on current position

             var x1 = GetXPos(ArrayLong[i-1],dc.getWidth()/2);

             var y1 = GetYPos(ArrayLat[i-1],dc.getHeight()/2);

             var x2 = GetXPos(ArrayLong[i],dc.getWidth()/2);

             var y2 = GetYPos(ArrayLat[i],dc.getHeight()/2);

                  

             //draw segment

      ShowTrajectLine(dc,x1,y1,x2,y2,Gfx.COLOR_WHITE);     

      }

      //to draw a line between to point

      function ShowTrajectLine(dc,x1,y1,x2,y2,cColor) {

          dc.setColor(cColor,Gfx.COLOR_TRANSPARENT);

          dc.setPenWidth(2);

        dc.drawLine(x1,y1,x2,y2);

      }

      //to get the X position (in pixels)

      function GetXPos(long,iWShift) {

             return zoom*scalefactor_pixel_longlat*(long-GetXCenter())+iWShift;

      }

That operates very well! But when the number of points is too high (for a long hiking for example), that takes time to redraw all points and watchdog tripped error is activated and then crash!

How “cut” this part of the code in order to reset the watchdog counter? I have no idea except with multithreading but it’s not possible with Garmin SDK. I imagine that there are some ways to manage such a problem.

Thanks’ for your help and advices!

 

Sylvain

  • The way I do this is I have something like

    maxDisplayPoints=100;

    then using the size of array, I display every point, every other point, every 3rd point, etc, so I never display more than maxDisplayPoints.

    So if there are 400 things in the array, only display every 4th one.

  • hello Jim,

    Thanks a lot for your advice! I will try a system with your idea.

    By past, I had imagined something like: each 10rd point, I store latitude and longitude, when the array is full to keep the whole map, I decrease the precision by erasing 1 point out 2 in the array and by changing the sampling from 10 to 20..and so on. I was not convinced at that time, I will retry.

    Thanks

    Sylvain