C API: `drawLine` API can "overdraw" by one pixel

In both the simulator and on hardware running 1.12.3, the C API drawLine appears to "overdraw" by one pixel for certain line widths.

I am reproducing this on macOS; and haven't tried on other OS'es nor have tried this with a Lua implementation.

Steps to reproduce:

  1. Draw a horizontal or vertical line at width 0 or 1
    • e.g.: playdate->graphics->drawLine(0, 0, 10, 0, 1, kColorBlack)
      • will result in a line that is rendered 11 pixels in length, rather than the expected 10

Expected result:

  • The line is drawn with the given length (eg: either x2 - x1 for horizontal lines, or y2 - y1 for vertical lines).

Observed result:

  • The line is drawn with a length + 1 from what I would expect; but only for width 1 (horizontal lines) and width 0 or 1 (vertical lines)

Diagonal line drawing may similarly be affected, I haven't investigated this yet.

Directionality of drawing the line does not affect the bug. The "overdraw" always occurs in the rightmost or bottommost direction.


Here is display output from a sample project that reproduces the issue. It draws 10 equal-length lines, increasing in width from 0 to 9. The lines are drawn in both "directions" (eg: left-to-right, right-to-left, top-to-bottom, bottom-to-top).

  1. Raw output of drawing the various lines:

    • 1_drawline_image
  2. A marked up version of the previous image, with an overlay to highlighting the issue. You may still need to zoom to observe it; it's difficult to see at 1x scale.

    • 1_drawline_image_with_markup

Also, for convenience in reproducing:

  • A pre-build pdx that should run in the simulator or hardware:

  • A complete project bundle with additional comments. NOTE: This is a single source project; if the SDK is on your path you should be able to make to build it and use the produced pdx.

4 Likes