[Solved] love.draw and RAM overuse

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
Crimson
Prole
Posts: 3
Joined: Wed Jan 11, 2012 6:20 pm

[Solved] love.draw and RAM overuse

Post by Crimson »

Hello! I'm new to this community, LÖVE, and Lua and am only somewhat acquainted with programming. I've read through Kikito's Love-Tile-Tutorial on GitHub as well as the Hamster Ball tutorial and use most of the code demonstrated there in the program I'm building now. I've also been through the 78 pages of this Support and Development forum reading anything with a title that might provide some clues as to why I'm experiencing the problem I'm having but didn't find anything directly related. (I did find tons of other useful things, though! :) )

What the program does:

Draws a tilemap to the screen using Kikito's string method
Draws a controllable character (Up, Down, Left, Right) to the screen from another tileset

The Problem: The program runs fully functioning for about 10 seconds, though with each passing second it uses 8% more RAM until the program crashes.

After some troubleshooting I believe I've pinpointed the issue to my function for drawing the character -

Code: Select all

function drawPlayer()
	playerImage = love.graphics.newImage('/tilesets/characters.png')
	fancyGhoul = love.graphics.newQuad(0, 0, 64, 64, 640, 640)
	love.graphics.drawq(playerImage, fancyGhoul, player.act_x, player.act_y)
end
This function is stored in a separate piece of code (Player-Functions.lua) and is called in Main.Lua at the love.draw function:

Code: Select all

function love.draw()
	drawMap()
	drawPlayer() 
end
When I delete the drawPlayer() function and just allow the map to be drawn, the program runs as expected, using a normal amount of RAM.

My first intuition was that redrawing the character every frame was using exponential amounts of RAM, if it saves a new character rather than overwrite the current one. However, my intuition isn't programming minded yet, so after trying some different things and failing I have come to you!
Last edited by Crimson on Fri Jan 13, 2012 10:21 pm, edited 1 time in total.
User avatar
Ellohir
Party member
Posts: 235
Joined: Sat Oct 22, 2011 11:12 pm

Re: love.draw and RAM overuse

Post by Ellohir »

Code: Select all

   playerImage = love.graphics.newImage('/tilesets/characters.png')
   fancyGhoul = love.graphics.newQuad(0, 0, 64, 64, 640, 640)
This variables do not have to be refreshed. Store them and keep only the drawq one on the drawPlayer function. That should do it (you are reading the tileset every frame, that's a heavy process).
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: love.draw and RAM overuse

Post by Robin »

Yeah, you don't need to create an image each frame to use it.

Keep those two assignments in love.load() instead.
Help us help you: attach a .love.
User avatar
Crimson
Prole
Posts: 3
Joined: Wed Jan 11, 2012 6:20 pm

Re: love.draw and RAM overuse

Post by Crimson »

That did it!

One of the things I tried was moving "fancyGhoul = love.graphics.newQuad(0, 0, 64, 64, 640, 640)" out as a global local variable, after reading about the problems people were having with constantly drawing newfonts, but that didn't solve it.

However, moving both of the variables out worked perfectly - thanks a bunch! It didn't occur to me that it would be checking the image every frame, I just kind of unconsciously assumed it was saved inside the code, which was a silly assumption in hindsight :P
Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot], Semrush [Bot] and 5 guests