Graphics OK in emulator but crashing on watch

Posted on
  • I want to draw lines of varying width and attach my test app. This runs fine in the emulator up to at least 100 iterations (see line 34), although it is slow. On my watch , however, it breaks while drawing the fourth line and the console shows:

    0
    1
    2
    3
    Execution Interrupted
    at line 1 col 237
    ...0,y0);e2=err;x2=x0;if(2*e2>=-dx){for(­e2+=dy,y2=y0;e2<ed*wd&&(y1!=y2...
                                         ^
    in function "drawLineWidth" called from line 3 col 38
      drawLineWidth(i*20,0,i*20+100,175,i);
                                         ^
    

    Process.memory() shows usage pretty steady at about 250 with 11750 free so if there is a memory leak I'm not seeing it.

    Any ideas how I can fix this? Thanks.


    1 Attachment

  • it is interesting that the display is 240x240 (bangle 1) and 176x176 (b2) and yet you use coordinates like i*20+100 for i up to 100. at 4 it is already at 180 so not sure what is the point

  • Well, my first version only drew five lines which does fit on a Bangle 2 - I increased it to 100 just to see if I could make it break on the emulator (and I couldn't). So far as I can tell the graphics system happily ignores coordinates outside the visible bounds, but anyway my problem occurs when trying to draw within the visible area.

    The attached image shows the device (black image) breaking partway through the final line, whereas the emulator (white) completes the last line.


    2 Attachments

    • lines bangle.png
    • lines emulator.png
  • I think your problem is just that you're uploading the code and executing it immediately.

    What happens is the IDE uploads the code, and then checks to see if the watch is responding. It's not because it's spending so long executing the code, so it tries to send commands to break out of execution.

    What you need is to execute your code after a delay - try this:

    function drawLineWidth(x0,y0,x1,y1,wd) {
    // Thanks to http://members.chello.at/~easyfilter/bre­senham.html
      if (wd==0) {// regular line if zero width
        g.drawLine(x0,y0,x1,y1);
        return;
      }
      let dx=Math.abs(x1-x0);
      let sx=(x0<x1)?1:-1;
      let dy=Math.abs(y1-y0);
      let sy=(y0<y1)?1:-1;
      let err = dx-dy, e2, x2, y2;
      let ed = (dx+dy == 0) ? 1 : Math.sqrt(dx*dx+dy*dy);
      wd=(wd+1)/2;
      for (wd = (wd+1)/2; ; ) {
        g.setPixel(x0,y0);
        e2=err;
        x2=x0;
        if (2*e2 >= -dx) {
          for (e2 += dy, y2 = y0; e2 < ed*wd && (y1 != y2 || dx > dy); e2 += dx)
            g.setPixel(x0, y2 += sy);
          if (x0 == x1) break;
          e2 = err; err -= dy; x0 += sx; 
        }
        if (2*e2 <= dy) { 
          for (e2+= dx-e2; e2 < ed*wd && (x1 != x2 || dx > dy); e2 += dy)
            g.setPixel(x2+=sx, y0);
          if (y0 == y1) break;
          err += dx; y0 += sy;       
        }
      }
    }
    
    setTimeout(function() {
      g.clear();
      for (let i=0;i<100;i++){
        print(process.memory());
        console.log(i);
        drawLineWidth(i*20,0,i*20+100,175,i);
      }
    }, 1000);
    
  • Many thanks, Gordon, that fixes the problem in my test app. I haven't yet got it working in the clock for which this was a prototype, but I will persevere!

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

Graphics OK in emulator but crashing on watch

Posted by Avatar for BillV @BillV

Actions