SetContext bug with WIDTH and HEIGHT

First of all, many thanks for this excellent program, and the amazing level of support.

I found a (minor) bug concerning the constants WIDTH and HEIGHT while using setContext()
By the way, i have Codea 1.4.1 and an ipad 1.

What happens is that in fullscreen mode width and height don’t hold the correct value if I use setcontext.
If I press the reset button (circular arrow on the bottom) then everything is alright again. next time I run the code however the problem returns.

here’s he minimum code needed to reproduce the behavior:
It’s supposed to draw one line completely from top-left to bottom-right, however the first time it draws it top-left to somewhere mid-right

function setup()
    displayMode(FULLSCREEN)
    img = image(WIDTH,HEIGHT)
    setContext(img)
        stroke(255,255,255,255)
        strokeWidth(5)
        line(0,0,WIDTH,HEIGHT)
    setContext()
end

function draw()
    background(0,0,0,255)
    stroke(255,255,255,255)
    strokeWidth(5)
    line(0,HEIGHT,WIDTH,0) 
end

If you comment out the line(0,0,WIDTH,HEIGHT) part in the setup the bug is gone.

Is it an error in my code or is something wrong with Codea?

This is a small bug having to do wih setting the displaymode inside the setup function. Move that line of code outside of setup as a workaround like this:

displayMode(FULLSCREEN)
function setup()
    --moved displayMode call up
    img = image(WIDTH,HEIGHT)
    setContext(img)
        stroke(255,255,255,255)
        strokeWidth(5)
        line(0,0,WIDTH,HEIGHT)
    setContext()
end

function draw()
    background(0,0,0,255)
    stroke(255,255,255,255)
    strokeWidth(5)
    line(0,HEIGHT,WIDTH,0) 
end

Now it works correctly.

Thanks! Works like a charm!

Is there any reason not to put all setup code out of the setup function in Main?

By the way, fast responses like this is another reason to love this program and its community.

I added the bug to the issue tracker; I could not see that it had been reported. This code also shows it:


function setup()
    displayMode(FULLSCREEN) 
    fill(255)
    stroke(255)
    strokeWidth(5)
    line(0, 0, 0, 0)
end

function draw()
    background(0)
    text(tostring(WIDTH)..", "..tostring(HEIGHT), WIDTH/2, HEIGHT/2)
    line(0, HEIGHT, WIDTH, 0) 
end