Something seems to be double-releasing in
setStencilPattern: all my code is Lua so I don't think I should be able to cause this bug.
main.lua:421: lua_release called on object with retainCount == 0 stack traceback: [C]: in field 'setStencilPattern' main.lua:421: in function 'playdate_update' main.lua:436: in function <main.lua:433>
The offending line is just
gfx.setStencilPattern(0.5); wrapping it (and the
gfx.drawLine it refers to) in a push/pop context pair makes the problem go away.
I'm sorry that I don't have a lot of time to create a genuine minimal example, but I was hoping this might either be a known problem or something obvious once you look at the API code.