There is something wrong with this code. Codea constantly crashes after this method is called for some 500 times from the
function Screen:scroll(pos, dim, lines) pushStyle() spriteMode(CORNER) rectMode(CORNER) fill(0, 0, 0, 255) noStroke() noSmooth() local topLeft = self:calculateActualLoc(pos) local bottomRight = vec2(topLeft.x+dim.x*8, topLeft.y-dim.y*8) if lines < 0 then local movedArea = self.buffer:copy(topLeft.x-1, bottomRight.y, dim.x*8, (dim.y+lines)*8+1) setContext(self.buffer) sprite(movedArea, topLeft.x-1, topLeft.y-movedArea.height) rect(topLeft.x-1, bottomRight.y, dim.x*8, -lines*8) elseif lines > 0 then local movedArea = self.buffer:copy(topLeft.x-1, bottomRight.y+lines*8, dim.x*8, (dim.y-lines)*8+1) setContext(self.buffer) sprite(movedArea, topLeft.x-1, bottomRight.y-1) rect(topLeft.x-1, topLeft.y-lines*8, dim.x*8, lines*8) end setContext() popStyle() end
I narrowed it further to the call to
image:copy() but I can’t reproduce it in a separate plain simple program. If the
copy line is commented out, no crash but of course it doesn’t do what it’s supposed to.
self.buffer is just
image(pixelDim.x, pixelDim.y) whose contents are drawn via both
image:set and graphic operations via
setContext(self.buffer) just like what this method does, all that before it’s
sprited onto screen.
The symptoms look to me that there’s some critical resource leak here when
image:copy is called, causing Codea to crash. But I’m not sure why same problem doesn’t show up when I simplified it into a plain separate program. I need help to get around this problem.