Compile Love for ImageData getPointer shortcut

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
JuniperBunny
Prole
Posts: 2
Joined: Sun May 11, 2014 2:15 am

Compile Love for ImageData getPointer shortcut

Post by JuniperBunny »

Hi, I tried all day yesterday to compile Love so I could add this one function, but I have bad luck with other people's code. I just need to bypass having to store ImageData in Lua and go straight to the pointer, and I was wondering if someone who already knows how to compile Love could do it for me real quick. This code might be incorrect, I don't know how the Lua interface works, but something like this. I'm hoping it's not a big deal, and I would be thankful to have it

Code: Select all

int w_Canvas_getImageDataPointer(lua_State *L)
{
	Canvas *canvas = luax_checkcanvas(L, 1);
	love::image::Image *image = luax_getmodule<love::image::Image>(L, "image", MODULE_IMAGE_T);
	love::image::ImageData *img = canvas->getImageData(image);
	
	//Data *t = luax_checkdata(L, 1);
	lua_pushlightuserdata(L, img->getData());
	return 1;
}
User avatar
slime
Solid Snayke
Posts: 3162
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: Compile Love for ImageData getPointer shortcut

Post by slime »

Canvas:getImageData basically takes a screenshot of the canvas and stores the screenshot in a new ImageData - the new ImageData needs to be stored somewhere that will properly deallocate the data when it's no longer referenced anywhere (normally Lua will take care of that for you.)

If the new ImageData is created (via canvas->getImageData) without making sure it will eventually be cleaned up properly, then you'll have a memory leak.
Additionally, if the pointer to the ImageData's memory is accessed after the ImageData is deallocated, bad / unexpected things will happen.
JuniperBunny
Prole
Posts: 2
Joined: Sun May 11, 2014 2:15 am

Re: Compile Love for ImageData getPointer shortcut

Post by JuniperBunny »

I don't want to create the data in Lua at all, and I thought img would be destroyed in the C code when it leaves scope

I thought there would be a constant address where the data for the canvas is stored, not something that has to be created over and over
Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests