If I have a canvas which I release, re-create, redraw and then draw to screen in the same frame, it seems to not make it in time, thus being rendered empty...
This isn't a huge problem if this canvas is rendered directly on-screen, then it might result in it not being there for a frame, but since the need for this is kinda rare, it's nothing major.
The real problem for me comes up when I need to draw this canvas to another canvas, (like when buffering a parallax background) which then doesn't actually get buffered and might not be replaced in quite a while...
I've put together a somewhat minimal example demonstrating the behaviour.
I just don't know how to work my way around it (or if I'm doing something fundamentally wrong)
Code: Select all
function love.load ()
small_canvas = love.graphics.newCanvas(100, 100)
big_canvas = love.graphics.newCanvas(400, 400)
counter = 0
end
function draw_small_canvas ()
love.graphics.setColor(0, 1, 0, 1)
love.graphics.rectangle('fill', 1, 1, 100, 100)
love.graphics.setColor(1, 0, 0, 1)
love.graphics.circle('fill', 50, 50, 50)
love.graphics.setCanvas()
love.graphics.setColor(1, 1, 1, 1)
end
function love.draw ()
counter = counter + 1
if counter > 60 then
small_canvas:release()
small_canvas = love.graphics.newCanvas(100, 100)
big_canvas:release()
big_canvas = love.graphics.newCanvas(400, 400)
love.graphics.setCanvas(small_canvas)
draw_small_canvas()
love.graphics.setCanvas()
--save smaller canvas into bigger one
love.graphics.setCanvas(big_canvas)
love.graphics.draw(small_canvas, 0, 0)
love.graphics.draw(small_canvas, 100, 0)
love.graphics.draw(small_canvas, 100, 100)
love.graphics.draw(small_canvas, 0, 100)
love.graphics.setCanvas()
counter = 0
end
love.graphics.draw(small_canvas, 0, 0)
love.graphics.draw(big_canvas, 150, 0)
end
function love.update (dt)
if love.keyboard.isDown("escape") then
love.event.quit()
end
end
Code: Select all
make win; wine win32/canvas_bug_test.exe
The problem does not occur if I run it normally on linux.
Any pointers on what I might be doing wrong, are highly appreciated, thanks in advance!
Edit: removed some unused code - thanks for pointing that out, zorg!