Unstable getImageData? (crash)

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.
User avatar
Twinmold
Prole
Posts: 7
Joined: Tue Mar 15, 2011 1:32 pm

Unstable getImageData? (crash)

Post by Twinmold »

Hello; I was doing some tests with framebuffers, and i've run into a quite frustrating issue. :x
Essentially, I'm trying to get the ImageData from a Framebuffer every cycle; after a while, I get a crash. I'm running 0.7.1 on Windows 7 (64 bits). In case it's important, I'm not running LÖVE from an installation.

I get about 960-970 cycles in the attached .love (there's a counter) before the crash. Please check it out if you have the time.

Code: Select all

function love.load()

someimage = love.graphics.newImage('someimage.png')
fb = love.graphics.newFramebuffer(800,600)

avariable = 0

end

function love.update()

id = fb:getImageData()

avariable = avariable + 1

end

function love.draw()

love.graphics.setRenderTarget(fb)
	love.graphics.draw(someimage,800/2,600/2,0,1,1,someimage:getWidth()/2,someimage:getHeight()/2)
love.graphics.setRenderTarget()
	love.graphics.draw(fb,0,0)

love.graphics.print(avariable,10,10)
	
end
Attachments
fbgid_crash.love
(34.07 KiB) Downloaded 154 times
User avatar
Adamantos
Prole
Posts: 27
Joined: Sun May 16, 2010 10:47 pm

Re: Unstable getImageData? (crash)

Post by Adamantos »

hi,

same happened on my computer... after 1001 cycles the program crashes.
In my process manager I could see, that love is eating all of my memory until the crash.

But your code looks fine... maybe the line
id = fb:getImageData()
is critical ??
User avatar
thelinx
The Strongest
Posts: 857
Joined: Fri Sep 26, 2008 3:56 pm
Location: Sweden

Re: Unstable getImageData? (crash)

Post by thelinx »

What OS are you guys running? It runs perfectly well for me on 64-bit Debian.
User avatar
Twinmold
Prole
Posts: 7
Joined: Tue Mar 15, 2011 1:32 pm

Re: Unstable getImageData? (crash)

Post by Twinmold »

Adamantos wrote:hi,

same happened on my computer... after 1001 cycles the program crashes.
In my process manager I could see, that love is eating all of my memory until the crash.

But your code looks fine... maybe the line
id = fb:getImageData()
is critical ??
Yep, it's clearly that function. It's obviously not made for continuous calling, but I don't think the problem is necessarily about memory (I get a steady framerate until the crash). Are you running the windows version too?
thelinx wrote:What OS are you guys running? It runs perfectly well for me on 64-bit Debian.
Windows (mind-parries collective groan) 7, 64-bit for me
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Unstable getImageData? (crash)

Post by Robin »

I'm on 64-bit Ubuntu, and for me the system slows down massively in the 1300-1500s, after which I closed LÖVE normally.
Help us help you: attach a .love.
User avatar
Twinmold
Prole
Posts: 7
Joined: Tue Mar 15, 2011 1:32 pm

Re: Unstable getImageData? (crash)

Post by Twinmold »

Robin wrote:I'm on 64-bit Ubuntu, and for me the system slows down massively in the 1300-1500s, after which I closed LÖVE normally.
Doesn't look like a bottleneck at all on my case (the performance is steady from load to crash), but I do get about 12% memory usage on my manager, when even graphics-intensive .loves usually keep under 10%.
User avatar
Ghuntar
Prole
Posts: 29
Joined: Wed Nov 25, 2009 8:56 am

Re: Unstable getImageData? (crash)

Post by Ghuntar »

On Ubuntu (32bit) :
At 300, my whole system tend to slow down because of high CPU usage (old centrino 1,2 GHz).
At 500, my 1GB memory begins to be full (yes I have an old, weak, but small laptop) and the swap begins, then CPU usage decreases (it waits from the slow HDD).
Then at 1000, my 2GB swap is almost full I have to kill love (I do not want to crash my computer).

I could test on a better laptop (Quad core i7/Too much RAM to be counted/64 bits and all this :P) later if it can help.
Crazy Little Thing Called LÖVE.
User avatar
leiradel
Party member
Posts: 184
Joined: Thu Mar 11, 2010 3:40 am
Location: Lisbon, Portugal

Re: Unstable getImageData? (crash)

Post by leiradel »

Let me try to guess what the problem is...

When you make a call to fb:getImageData() a new image data is created, which has all pixels from the frame buffer so the memory requirements for it is width*height*bpp (where bpp is probably 4.) But on the Lua side of things what is created is a Proxy userdata, which takes only a handful of bytes and points to the actual image data object.

So the problem is, Lua doesn't see a need to trigger the garbage collection because for it each image data object takes only the size of a Proxy when in fact the each of these proxies point to an image data which takes far more memory. So the RAM is exhausted and eventually the computer begins to swap pages, slows down, and crashes (Windows, Linux will probably do something wiser.)

The need to inform Lua about the total size of an userdata, which in this case would include the size of the image data, comes up in its mailing list from time to time, but it was never added to the API. I don't remember if there's an workaround for that besides always allocating memory through lua_newuserdata and using luaL_ref/unref on them to avoid them being collected when still being pointed to by other objects.

In this specific case, maybe fb:getImageData() could optionally accept an image data parameter the same size of the frame buffer, which would be used to get the frame buffer pixels instead of creating a new image data?
User avatar
miko
Party member
Posts: 410
Joined: Fri Nov 26, 2010 2:25 pm
Location: PL

Re: Unstable getImageData? (crash)

Post by miko »

Adamantos wrote:hi,

same happened on my computer... after 1001 cycles the program crashes.
In my process manager I could see, that love is eating all of my memory until the crash.
Same for me - at about 1500 I get love crash, and top shows it gets almost 3GB of RAM. Clearly a memory leak somewhere (maybe in underlaying DevIL library).
I am using love-jit on linux 32bit.
My lovely code lives at GitHub: http://github.com/miko/Love2d-samples
User avatar
leiradel
Party member
Posts: 184
Joined: Thu Mar 11, 2010 3:40 am
Location: Lisbon, Portugal

Re: Unstable getImageData? (crash)

Post by leiradel »

miko wrote:Clearly a memory leak somewhere
I'm pretty sure there's no memory leak, it's just the way Lua handles user data.
Post Reply

Who is online

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