[SOLVED] setCanvas() expects a number argument?

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
NetherGranite
Prole
Posts: 30
Joined: Wed Jul 11, 2018 11:08 pm

[SOLVED] setCanvas() expects a number argument?

Post by NetherGranite »

I'm getting this error:

Code: Select all

main.lua:346: bad argument #2 to 'setCanvas' (number expected, got no value)
What number am I supposed to be giving it?

Trying to pass 0 to it gives me this error:

Code: Select all

main.lua:346: Invalid slice index: 0.
To clarify, this is love.graphics.setCanvas(canvas1, canvas2, …) that I'm trying to call.
Last edited by NetherGranite on Wed Oct 24, 2018 12:15 am, edited 1 time in total.
User avatar
pgimeno
Party member
Posts: 3548
Joined: Sun Oct 18, 2015 2:58 pm

Re: setCanvas() expects a number argument?

Post by pgimeno »

Works for me.

Code: Select all

local canvas1 = love.graphics.newCanvas()
local canvas2 = love.graphics.newCanvas()
love.graphics.setCanvas(canvas1, canvas2)
love.graphics.setCanvas()
You'll need to provide more information.
User avatar
slime
Solid Snayke
Posts: 3132
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: setCanvas() expects a number argument?

Post by slime »

If the canvas is an array texture or cubemap or 3D texture, you need to give it a layer/cube index to render to as an argument in setCanvas.
User avatar
NetherGranite
Prole
Posts: 30
Joined: Wed Jul 11, 2018 11:08 pm

Re: setCanvas() expects a number argument?

Post by NetherGranite »

It turns out this happens if you try to pass three numbers to newCanvas(), e.g. love.graphics.newCanvas(1920, 1080, 5). This is because the third argument is how many layers the canvas should have; as a result, setCanvas() now expects a number argument telling it which layer of the canvas to use.

I should add the disclaimer that this is my best guess since such behavior is undocumented as of writing this. I have bought up this lack of documentation in this post.
Post Reply

Who is online

Users browsing this forum: No registered users and 24 guests