Page 1 of 1

[SOLVED] Canvas is crashing 11.2

Posted: Sun Jan 20, 2019 10:27 pm
by DGM
Hello,

I'm using v11.2 in 64-bit Windows 10. Trying to use a canvas causes an immediate crash, even with the following minimal code:

Code: Select all

function love.load()
	canvas_1 = love.graphics.newCanvas()
end

function love.update()

end

function love.draw()
	love.graphics.setCanvas(canvas_1)
end
Here's the error message:

Code: Select all

Error

boot.lua:514: present cannot be called while a Canvas is active.


Traceback

[C]: in function 'present'
[C]: in function 'xpcall'
I've tried moving setCanvas to update() and moving the newCanvas command outside load(), but the results are the same. I tinkered with canvases a bit in the previous version and don't remember having this problem, so am I correct in assuming this is a bug in 11.2 or am I doing something wrong?

Re: Canvas is crashing 11.2

Posted: Sun Jan 20, 2019 10:52 pm
by pgimeno
When love.draw finishes, you need to have no canvas active, so you need to disable it at some point before the end of love.draw(). This works, for example:

Code: Select all

function love.draw()
	love.graphics.setCanvas(canvas_1)
	-- do stuff here
	love.graphics.setCanvas()
end
Of course, drawing only to a canvas in love.draw and not to the screen isn't very useful, but then your example had the same problem; it's only for illustrative purposes. Here's something a bit more useful:

Code: Select all

function love.draw()
	love.graphics.setCanvas(canvas_1)
	-- do stuff here
	love.graphics.setCanvas()
	love.graphics.draw(canvas_1)
end

Re: Canvas is crashing 11.2

Posted: Sun Jan 20, 2019 11:02 pm
by DGM
pgimeno wrote: Sun Jan 20, 2019 10:52 pm When love.draw finishes, you need to have no canvas active, so you need to disable it at some point before the end of love.draw(). This works, for example:
That was the problem. Thanks.

Suggestion to the Love2D devs: a warning about needing to deactivate your canvases in the documentation for the canvas feature might be a good idea.

Re: Canvas is crashing 11.2

Posted: Sun Jan 20, 2019 11:42 pm
by pgimeno
I've added a paragraph to love.graphics.setCanvas, feel free to correct it if you think the wording could be improved (wiki accounts use the same user/password as the forum). To prevent confusion: I'm not a Love2d dev.