Codea crash

Don’t know what it is, but here’s the code running on an iPad 2

function setup()
   displayMode(FULLSCREEN)
   
end
framenum = 0
function draw()
    background(255, 0, 0, 255)
    sprite(img(),WIDTH,HEIGHT)
    tileImage(img(),0,0,1)
    fill(72, 255, 0, 255)
    text(WIDTH,CurrentTouch.x,CurrentTouch.y)
    text(HEIGHT,CurrentTouch.x+34,CurrentTouch.y)
end

function img()
local img = image(8, 8)
img:set(1,1,0,0,0,255)
img:set(1,2,255,255,255,255)
img:set(1,3,0,0,0,255)
img:set(1,4,255,255,255,255)
img:set(1,5,0,0,0,255)
img:set(1,6,255,255,255,255)
img:set(1,7,0,0,0,255)
img:set(1,8,255,255,255,255)
img:set(2,1,255,255,255,255)
img:set(2,2,0,0,0,255)
img:set(2,3,255,255,255,255)
img:set(2,4,0,0,0,255)
img:set(2,5,255,255,255,255)
img:set(2,6,0,0,0,255)
img:set(2,7,255,255,255,255)
img:set(2,8,0,0,0,255)
img:set(3,1,0,0,0,255)
img:set(3,2,255,255,255,255)
img:set(3,3,0,0,0,255)
img:set(3,4,255,255,255,255)
img:set(3,5,0,0,0,255)
img:set(3,6,255,255,255,255)
img:set(3,7,0,0,0,255)
img:set(3,8,255,255,255,255)
img:set(4,1,255,255,255,255)
img:set(4,2,0,0,0,255)
img:set(4,3,255,255,255,255)
img:set(4,4,0,0,0,255)
img:set(4,5,255,255,255,255)
img:set(4,6,0,0,0,255)
img:set(4,7,255,255,255,255)
img:set(4,8,0,0,0,255)
img:set(5,1,0,0,0,255)
img:set(5,2,255,255,255,255)
img:set(5,3,0,0,0,255)
img:set(5,4,255,255,255,255)
img:set(5,5,0,0,0,255)
img:set(5,6,255,255,255,255)
img:set(5,7,0,0,0,255)
img:set(5,8,255,255,255,255)
img:set(6,1,255,255,255,255)
img:set(6,2,0,0,0,255)
img:set(6,3,255,255,255,255)
img:set(6,4,0,0,0,255)
img:set(6,5,255,255,255,255)
img:set(6,6,0,0,0,255)
img:set(6,7,255,255,255,255)
img:set(6,8,0,0,0,255)
img:set(7,1,0,0,0,255)
img:set(7,2,255,255,255,255)
img:set(7,3,0,0,0,255)
img:set(7,4,255,255,255,255)
img:set(7,5,0,0,0,255)
img:set(7,6,255,255,255,255)
img:set(7,7,0,0,0,255)
img:set(7,8,255,255,255,255)
img:set(8,1,255,255,255,255)
img:set(8,2,0,0,0,255)
img:set(8,3,255,255,255,255)
img:set(8,4,0,0,0,255)
img:set(8,5,255,255,255,255)
img:set(8,6,0,0,0,255)
img:set(8,7,255,255,255,255)
img:set(8,8,0,0,0,255)
return img

    
end

function tileImage(image,movex,movey,iscale)   
    currentScale = scale()
    bscale = currentScale
    scale(iscale)
    ssx, ssy = spriteSize(image)
    for y = 0, WIDTH/ssx+1 do
        for x = 0, HEIGHT/ssy+1 do
            sprite(image, x * ssx, y * ssy)
        end
    end
    redefineScale()
end

function redefineScale()
    local oldScale = scale
    local currentScale = 1
    scale = function( d )
        if d == nil then
            return currentScale
        else
            currentScale = currentScale * d 
            oldScale(d)
        end
    end
end

Code is supposed to pause when there’s a memory overload, right?

You shouldn’t allocate a new image every frame. That’s just asking for trouble. Put the creation of the img in setup. I guess you did it on purpose to show that you can crash Codea by overloading the memory. But it is easily avoidable.

I know that @Herwig, but thank you. I was just saying that Codea is supposed to pause the program when there is a memory overload.

Actually crashing is what you would expect, since we can’t stop the operating system from shutting down the app, and we don’t know how much free memory we are allowed to use before the watchdog pulls the plug.

Alright.

One thing we can do to help with this issue if enforce garbage collection when the app receives a low memory warning. This wont guarantee that the OS wont terminate Codea, but it will help in a lot of cases I think.

Demibooks composer has a little gauge that tells you how much memory is expected to be used. That’s harder to do with Codea though. This is why I was saying not to use importImage(URL) because it might accidentally be put in the draw loop.