Regression in sprite dirty rects with drawLine

After upgrading my project to the newest SDK (v1.10.0) I noticed stray pixels appearing.
I'm using the sprite system and additionally I'm drawing a little crank indicator using drawLine.
playdate-20220502-193022
It still worked with SDK v1.4.0. And comparing in the different Simulator versions, one can see the dirty rect area being significantly larger than in the newest version.

A small example to reproduce it:

import "CoreLibs/graphics"
import "CoreLibs/sprites"

local gfx = playdate.graphics

function backgroundDrawCallback( x, y, width, height )
  -- background would be drawn here
end

function setup()
  gfx.setBackgroundColor(gfx.kColorBlack)
  gfx.sprite.setBackgroundDrawingCallback(backgroundDrawCallback)
  playdate.display.setScale(4)
end

function playdate.update()
  --gfx.clear()
  gfx.sprite.update()

  if not playdate.isCrankDocked() then
    local hMid = playdate.display.getWidth() / 2
    local vMid = playdate.display.getHeight() / 2
    crankPos = playdate.getCrankPosition()
    local crankY = math.sin(math.rad(crankPos - 90)) * 10
    local zDepth = math.sin(math.rad(crankPos)) / 2 + 0.35
  
    gfx.setColor(gfx.kColorWhite)
    gfx.setLineWidth(4)
    gfx.setLineCapStyle(gfx.kLineCapStyleRound)
    gfx.drawLine(hMid + 3, vMid, hMid + 10, vMid)
    gfx.setDitherPattern(zDepth)
    gfx.drawLine(hMid + 10, vMid, hMid + 10, vMid + crankY)
    gfx.drawLine(hMid + 10, vMid + crankY, hMid + 20, vMid + crankY)
  end
end

setup()

ah, found it! I changed the drawing functions to return the rect they drew in so we can easily mark it as needing update in the sprite system, but on wide lines I forgot to include the round endcaps. Oops. A fix is in the pipeline!

1 Like