Error when creating canvas

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
Luke100000
Party member
Posts: 232
Joined: Mon Jul 22, 2013 9:17 am
Location: Austria
Contact:

Error when creating canvas

Post by Luke100000 »

Hello,

My game receives this error when creating a new normal 8rgba canvas where I do not know why:
"Cannot create canvas: Texture format cannot be rendered to on this system."

I can reproduce this error when creating thousands of canvases until my system runs out of memory, but I'm very sure my game doesn't do this and it still crashes, sometimes early, sometimes later and not always. My game uses canvases to render chunks of the world and the amount of canvases can easily be limited, but as I said I do not think it reached a limit. On my cheap netbook, 2GB RAM, and maybe ~512 MB VRAM I can create 2200 512x512 8rgba canvases.

Are there any other reasons this error might appear?
CameronGoble
Prole
Posts: 3
Joined: Fri Sep 15, 2017 2:14 am

Re: Error when creating canvas

Post by CameronGoble »

I encountered the same issue and found your message on the forums. I was using code to create a canvas object out of a Text object so I could do interesting transforms on it:

Code: Select all

function textToCanvasObject(textObject)
    -- Maybe draw text onto a canvas first?
    local h = textObject:getHeight()
    local w = textObject:getWidth()
    local textCanvas = love.graphics.newCanvas( w, h )
    textCanvas:renderTo( 
      function()
        love.graphics.clear()
        love.graphics.draw(textObject, 0,0)
      end
    )
  return canvasObject
end
I solved it by reviewing the textObject parameter I was passing that object. I forgot to properly index the object from the function call in another segment of code, so h and w were coming out to be zero. That's what threw the error. See the difference here:

Code: Select all

nameText = textToCanvasObject(love.graphics.newText(crisisFont, crisisList[i].name))
vs.

Code: Select all

nameText = textToCanvasObject(love.graphics.newText(crisisFont, name))
THe first worked, the second gave the error. Try re-checking any parameters you send to newCanvas().
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Google [Bot] and 48 guests