[solved] love.graphics.newImage causes memory leak in MacOS?

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
User avatar
Sasha264
Party member
Posts: 131
Joined: Mon Sep 08, 2014 7:57 am

[solved] love.graphics.newImage causes memory leak in MacOS?

Post by Sasha264 »

Hello everyone =)

I'm trying to create some textures from code, and noticed some strange behaviour.
Please look at [1] and [2] lines of my code. With image:refresh() [2] code works fine on Windows and on MacOS, but with love.graphics.newImage(...) [1] in Windows works fine, but in MacOS it causes memory leak and then crash love http://monosnap.com/image/n8oHMiVtuUFyi ... DnLzcEtUif
Note: I have love 0.9.1. Image:refresh() is the great method, but in some cases creating new images would be more convenient...
Can anyone help me please? (:

Code: Select all

function love.load()
	w = 512
	h = 512
	love.window.setMode(w, h, {resizable=false, vsync=false})

	imageData = love.image.newImageData(w, h)
	image = love.graphics.newImage(imageData)
end

function love.update(dt)
	for i = 0, w-1 do
		for j = 0, h-1 do
			imageData:setPixel(i, j, 255, 255, 255, math.random(0, 255))
		end
	end

	image = love.graphics.newImage(imageData) -- [1] memory leak?
	-- image:refresh() -- [2] works fine
end

function love.draw()
	love.window.setTitle("fps " .. love.timer.getFPS())
	love.graphics.draw(image, 0, 0)
end
Last edited by Sasha264 on Fri Dec 01, 2017 7:12 pm, edited 1 time in total.
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: love.graphics.newImage causes memory leak in MacOS?

Post by Robin »

Welcome!

[wiki]love.graphics.newImage[/wiki] is one of the functions where it is documented that it is not a good idea to call them every frame, so that is expected behavior. I doubt the devs will see this as a bug, but if you want to you can report it on the issue tracker.
Help us help you: attach a .love.
jjmafiae
Party member
Posts: 1331
Joined: Tue Jul 24, 2012 8:22 am

Re: love.graphics.newImage causes memory leak in MacOS?

Post by jjmafiae »

as Robin said don't run this every frame and in the next version of löve (0.9.2) love.gfx.newImage uses less RAM.
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: love.graphics.newImage causes memory leak in MacOS?

Post by bartbes »

You are supposed to use refresh for this, to prevent creating lots of garbage, and it seems that your crash is simply a result of the garbage collection not being run fast enough. It is of course possible that there is a memory leak, but it's unlikely.
jjmafiae
Party member
Posts: 1331
Joined: Tue Jul 24, 2012 8:22 am

Re: love.graphics.newImage causes memory leak in MacOS?

Post by jjmafiae »

to run garbage collector do this: collectgarbage()

But I have never seen anyone that actually needed to run love.gfx.newImage every frame.
User avatar
Plu
Inner party member
Posts: 722
Joined: Fri Mar 15, 2013 9:36 pm

Re: love.graphics.newImage causes memory leak in MacOS?

Post by Plu »

What are you trying to accomplish, anyway? There's probably a better way for it.
User avatar
Sasha264
Party member
Posts: 131
Joined: Mon Sep 08, 2014 7:57 am

Re: love.graphics.newImage causes memory leak in MacOS?

Post by Sasha264 »

collectgarbage() solves the problem, and now on MacOS and on Windows memory consumption are the same.
So that was obviously not a memory leak.
Yes, I'm not going to call love.graphics.newImage every frame, only when I need it. This example was just for clarity.

Thanks for the help ^_^
Plu wrote:What are you trying to accomplish, anyway?
I want to try some kind of "procedural textures". Is here any links for examples in love?
User avatar
Plu
Inner party member
Posts: 722
Joined: Fri Mar 15, 2013 9:36 pm

Re: love.graphics.newImage causes memory leak in MacOS?

Post by Plu »

Shouldn't the texture be more or less fixed after it's first render? I can only imagine that right now it's either constantly jittering because it looks a little different on each run.

I think you basic approach seems about right (except you should probably do it using a Shader because those are infinitely faster) but you shouldn't be redoing it every frame. You should draw the textures once and then just constantly redraw the same image.
User avatar
Sasha264
Party member
Posts: 131
Joined: Mon Sep 08, 2014 7:57 am

Re: love.graphics.newImage causes memory leak in MacOS?

Post by Sasha264 »

Plu, yes you a right, shaders are proper place for this experiments :cool:

Anyway the initial problem was solved by the call of garbage collector.
Thanks amigos! :awesome:
Post Reply

Who is online

Users browsing this forum: No registered users and 57 guests