robbielyman / seamstress

seamstress is an art engine
GNU General Public License v3.0
123 stars 12 forks source link

crash when 'screen.circle' is given a radius less than 2 #62

Closed dndrks closed 1 year ago

dndrks commented 1 year ago

morniiiiin' :) i have been running the same script for a few months which sometimes draws various-sized circles to the script window -- idk how i avoided this before tonight, but i can verify that it happens on all recent builds (tested back to 0.20.2) and i think i've tracked it down to a root cause!

running 0.20.6 on macOS 13.5.2 (w/M1 Pro)

test script

function init()
  radius = 1 -- if < 2, will crash
  clock.run(function()
    while true do
      clock.sleep(1 / 15)
      redraw()
    end
  end)
end

function redraw()
  screen.clear()
  screen.color(math.random(255), 255, 255)
  screen.move(10, 20)
  screen.circle(radius)
  screen.refresh()
end

to reproduce the issue: when the script is running, focus the script's main window -- focusing params doesn't seem to reliably trigger it. seems to occur with all radius values less than 2 (eg. 1.99).

to avoid the issue: change radius to 2 or higher :)

errors

when the repro conditions are met, seamstress crashes with either of the following messages:

if it crashes at load:

> zsh: bus error

if it doesn't crash at load, but the script window is manually focused (either clicked or cycled with keyboard shortcuts):

> seamstress(1870,0x1e851a080) malloc: Heap corruption detected, free list is damaged at 0x60000108f480
*** Incorrect guard value: 163208757268
seamstress(1870,0x1e851a080) malloc: *** set a breakpoint in malloc_error_break to debug
zsh: abort
robbielyman commented 1 year ago

hi!! thank you again for the clear issue! the problem, essentially, is that screen.circle() will draw 8 pixels when given a radius of one, but wasn't being given 8 pixels of room to do that in. now it is :)